66; ; Author: Shen, Jen-Chieh <jcs090218@gmail.com>
77; ; Description: Common way of sorting the CSS attributes.
88; ; Keyword: Common CSS Handy Sort Sorting
9- ; ; Version: 0.0.2
9+ ; ; Version: 0.0.5
1010; ; Package-Requires: ((emacs "24.4") (s "1.12.0") (cl-lib "0.6"))
1111; ; URL: https://github.com/jcs090218/com-css-sort
1212
4848 " Type of sorting CSS attributes algorithm going to use to sort.
4949'type-sort : Sort by Type Group.
5050'alphabetic-sort : Sort by Alphabetic Order."
51- :type 'symbol
51+ :type '(choice (const :tag " type-sort" type-sort)
52+ (const :tag " alphabetic-sort" alphabetic-sort))
5253 :group 'com-css-sort )
5354
5455(defcustom com-css-sort-sort-file " sort-order.config"
@@ -143,8 +144,7 @@ This wil replace `com-css-sort-default-attributes-order' if it can."
143144
144145
145146(defun com-css-sort-get-string-from-file (file-path )
146- " Return file-path's file content.
147- FILE-PATH : file path."
147+ " Return FILE-PATH's file content."
148148 (with-temp-buffer
149149 (insert-file-contents file-path)
150150 (buffer-string )))
@@ -162,22 +162,6 @@ FILE-PATH : file path."
162162 ; ; Return the sort order list.
163163 attr-list))
164164
165- ;;;### autoload
166- (defun com-css-sort-move-line-up ()
167- " Move up the current line."
168- (transpose-lines 1 )
169- (forward-line -2 )
170- (indent-according-to-mode ))
171-
172- ;;;### autoload
173- (defun com-css-sort-move-line-down ()
174- " Move down the current line."
175- (forward-line 1 )
176- (transpose-lines 1 )
177- (forward-line -1 )
178- (indent-according-to-mode ))
179-
180- ;;;### autoload
181165(defun com-css-sort-back-to-indentation-or-beginning ()
182166 " Toggle between first character and beginning of line."
183167 (when (= (point ) (progn (back-to-indentation ) (point )))
@@ -197,50 +181,48 @@ FILE-PATH : file path."
197181 (setq begin-line-point (point ))
198182 (= begin-line-point current-point))))
199183
200- ;;;### autoload
201184(defun com-css-sort-goto-first-char-in-line ()
202185 " Goto beginning of line but ignore 'empty characters'(spaces/tabs)."
203186 (com-css-sort-back-to-indentation-or-beginning)
204187 (when (com-css-sort-is-beginning-of-line-p)
205188 (com-css-sort-back-to-indentation-or-beginning)))
206189
207- ;;;### autoload
208190(defun com-css-sort-current-line-empty-p ()
209191 " Current line empty, but accept spaces/tabs in there. (not absolute)."
210192 (save-excursion
211193 (beginning-of-line )
212194 (looking-at " [[:space:]\t ]*$" )))
213195
214- (defun com-css-sort-is-inside-comment-block-p ()
196+ (defun com-css-sort-- is-inside-comment-block-p ()
215197 " Check if current cursor point inside the comment block."
216198 (nth 4 (syntax-ppss )))
217199
218- (defun com-css-sort-attribute-line ()
200+ (defun com-css-sort-- attribute-line ()
219201 " Check if current line the attribute line.
220202If non-nil, attribute line.
221203If nil, is not attribute line."
222204 ; ; Check attribute line by simply searching key character ':' colon.
223205 (string-match-p " :" (com-css-sort-get-current-line)))
224206
225- (defun com-css-sort-currnet-line-not-attribute-comment-line ()
207+ (defun com-css-sort-- currnet-line-not-attribute-comment-line ()
226208 " Check if current line is a 'pure' comment line, not an attribute comment line."
227209 (save-excursion
228210 (com-css-sort-goto-first-char-in-line)
229211 (forward-char 1 )
230212 (forward-char 1 )
231213 (and
232214 ; ; First check if is comment line.
233- (com-css-sort-is-inside-comment-block-p)
215+ (com-css-sort-- is-inside-comment-block-p)
234216 ; ; Then check if current line attribute line.
235- (not (com-css-sort-attribute-line)))))
217+ (not (com-css-sort-- attribute-line)))))
236218
237219(defun com-css-sort-get-sort-list-until-empty-or-comment-line ()
238220 " Get the list we want to sort.
239221Depends on if we meet a empty line or a comment line."
240222 (save-excursion
241223 (let ((line-list '()))
242224 (while (and (not (com-css-sort-current-line-empty-p))
243- (not (com-css-sort-currnet-line-not-attribute-comment-line)))
225+ (not (com-css-sort-- currnet-line-not-attribute-comment-line)))
244226 (let ((current-line (com-css-sort-get-current-line)))
245227 (when (not (string-match " }" current-line))
246228 ; ; Push the line into list.
@@ -251,26 +233,24 @@ Depends on if we meet a empty line or a comment line."
251233 ; ; Returns the list.
252234 line-list)))
253235
254- ;;;### autoload
255- (defun com-css-sort-next-blank-or-comment-line ()
236+ (defun com-css-sort--next-blank-or-comment-line ()
256237 " Move to the next line containing nothing but whitespace or \
257238first character is a comment line."
258239 (forward-line 1 )
259240 (while (and (not (com-css-sort-current-line-empty-p))
260- (not (com-css-sort-currnet-line-not-attribute-comment-line)))
241+ (not (com-css-sort-- currnet-line-not-attribute-comment-line)))
261242 (forward-line 1 )))
262243
263- ;;;### autoload
264- (defun com-css-sort-next-non-blank-or-comment-line ()
244+ (defun com-css-sort--next-non-blank-or-comment-line ()
265245 " Move to the next line that is exactly the code.
266246Not the comment or empty line."
267247 (forward-line 1 )
268248 (while (and (or (com-css-sort-current-line-empty-p)
269- (com-css-sort-currnet-line-not-attribute-comment-line))
249+ (com-css-sort-- currnet-line-not-attribute-comment-line))
270250 (not (= (point ) (point-max ))))
271251 (forward-line 1 )))
272252
273- (defun com-css-sort-beginning-of-attribute-block (start )
253+ (defun com-css-sort-- beginning-of-attribute-block (start )
274254 " Get the beginning of the attribute block.
275255START : current point."
276256 (goto-char start)
@@ -279,7 +259,7 @@ START : current point."
279259 (beginning-of-line )
280260 (point ))
281261
282- (defun com-css-sort-end-of-attribute-block (start )
262+ (defun com-css-sort-- end-of-attribute-block (start )
283263 " Get the end of the attribute block.
284264START : current point."
285265 (goto-char start)
@@ -288,14 +268,13 @@ START : current point."
288268 (end-of-line )
289269 (point ))
290270
291- (defun com-css-sort-insert-line-list (line-list )
292- " Insert list of line.
293- LINE-LIST : list of line."
271+ (defun com-css-sort--insert-line-list (line-list )
272+ " Insert list of line, LINE-LIST."
294273 (save-excursion
295274 (dolist (line line-list)
296275 (insert line))))
297276
298- (defun com-css-sort-swap-list-element (lst index-a index-b )
277+ (defun com-css-sort-- swap-list-element (lst index-a index-b )
299278 " Swap the element by using two index.
300279LST : list of array to do swap action.
301280INDEX-A : a index of the element.
@@ -348,8 +327,7 @@ LINE-LIST : list of line."
348327 ; ; Treat this as a `pair' data structure.
349328 (push index index-list)
350329 (push in-line return-line-list))
351- (progn
352- (error " You try to sort an CSS attribute that does not in the sort list : %s " first-word-in-line)))))
330+ (error " You try to sort an CSS attribute that does not in the sort list : %s " first-word-in-line))))
353331
354332 ; ; Bubble sort the elements.
355333 (let ((index-i 0 )
@@ -372,15 +350,15 @@ LINE-LIST : list of line."
372350
373351 (when (< value-b value-a)
374352 ; ; Swap index.
375- (com-css-sort-swap-list-element index-list
376- index-b
377- index-a)
353+ (com-css-sort-- swap-list-element index-list
354+ index-b
355+ index-a)
378356 ; ; Swap value with same index.
379- ; ; NOTE(jenchieh) : we do this much is all because
357+ ; ; NOTE: we do this much is all because
380358 ; ; of this line of code.
381- (com-css-sort-swap-list-element return-line-list
382- index-b
383- index-a)
359+ (com-css-sort-- swap-list-element return-line-list
360+ index-b
361+ index-a)
384362
385363 ; ; Set flag.
386364 (setq flag t )))
@@ -403,8 +381,8 @@ NO-BACK-TO-LINE : Do not go back to the original line."
403381 (save-window-excursion
404382 ; ; Ready to start sorting in the block.
405383 (let ((current (point ))
406- (start (com-css-sort-beginning-of-attribute-block (point )))
407- (end (com-css-sort-end-of-attribute-block (point ))))
384+ (start (com-css-sort-- beginning-of-attribute-block (point )))
385+ (end (com-css-sort-- end-of-attribute-block (point ))))
408386 ; ; Goto beginning of the attribute block.
409387 (goto-char start)
410388
@@ -417,7 +395,7 @@ NO-BACK-TO-LINE : Do not go back to the original line."
417395
418396 (when (>= (length line-list) 2 )
419397 (save-excursion
420- (com-css-sort-next-blank-or-comment-line)
398+ (com-css-sort-- next-blank-or-comment-line)
421399
422400 ; ; Find the last point
423401 (let ((record-point (point )))
@@ -432,25 +410,25 @@ NO-BACK-TO-LINE : Do not go back to the original line."
432410 ; ; Delete region.
433411 (delete-region current end-region-point)
434412
435- ; ; NOTE(jenchieh) : Design your sort algorithms here
413+ ; ; NOTE: Design your sort algorithms here
436414 ; ; depend on the type.
437- (cond (; ; OPTION(jenchieh) : Sort by Type Group.
415+ (cond (; ; OPTION: Sort by Type Group.
438416 (string= com-css-sort-sort-type 'type-sort )
439417 (progn
440418 (setq line-list (com-css-sort-sort-line-list-by-type-group line-list))))
441- (; ; OPTION(jenchieh) : Sort by Alphabetic Order.
419+ (; ; OPTION: Sort by Alphabetic Order.
442420 (string= com-css-sort-sort-type 'alphabetic-sort )
443421 (progn
444422 (setq line-list (sort line-list 'string< )))))
445423
446424 ; ; Insert the lines.
447- (com-css-sort-insert-line-list line-list)))
425+ (com-css-sort-- insert-line-list line-list)))
448426
449427 ; ; Goto next blank line or comment line.
450- (com-css-sort-next-blank-or-comment-line)
428+ (com-css-sort-- next-blank-or-comment-line)
451429
452430 ; ; Then goto next code line.
453- (com-css-sort-next-non-blank-or-comment-line)))))
431+ (com-css-sort-- next-non-blank-or-comment-line)))))
454432
455433 (when (not no-back-to-line)
456434 (with-no-warnings
@@ -471,7 +449,7 @@ NO-BACK-TO-LINE : Do not go back to the original line."
471449 (com-css-sort-attributes-block t )
472450
473451 ; ; Goto next blank line
474- (com-css-sort-next-blank-or-comment-line))))
452+ (com-css-sort-- next-blank-or-comment-line))))
475453
476454 ; ; make sure go back to the starting line.
477455 (with-no-warnings
0 commit comments