;ELC ;;; Compiled by cyd@localhost on Mon Apr 23 22:21:09 2007 ;;; from file /home/cyd/emacs/lisp/sort.el ;;; in Emacs version 22.0.99 ;;; with all optimizations. ;;; This file uses dynamic docstrings, first added in Emacs 19.29. (if (and (boundp 'emacs-version) (< (aref emacs-version (1- (length emacs-version))) ?A) (or (and (boundp 'epoch::version) epoch::version) (string-lessp emacs-version "19.29"))) (error "`sort.el' was compiled for Emacs 19.29 or later")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (custom-declare-group 'sort nil "Commands to sort text in an Emacs buffer." :group 'data) #@59 *Non-nil if the buffer sort functions should ignore case. (custom-declare-variable 'sort-fold-case 'nil '(#$ . -645) :group 'sort :type 'boolean) #@1722 General text sorting routine to divide buffer into records and sort them. We divide the accessible portion of the buffer into disjoint pieces called sort records. A portion of each sort record (perhaps all of it) is designated as the sort key. The records are rearranged in the buffer in order by their sort keys. The records may or may not be contiguous. Usually the records are rearranged in order of ascending sort key. If REVERSE is non-nil, they are rearranged in order of descending sort key. The variable `sort-fold-case' determines whether alphabetic case affects the sort order. The next four arguments are functions to be called to move point across a sort record. They will be called many times from within sort-subr. NEXTRECFUN is called with point at the end of the previous record. It moves point to the start of the next record. It should move point to the end of the buffer if there are no more records. The first record is assumed to start at the position of point when sort-subr is called. ENDRECFUN is called with point within the record. It should move point to the end of the record. STARTKEYFUN moves from the start of the record to the start of the key. It may return either a non-nil value to be used as the key, or else the key is the substring between the values of point after STARTKEYFUN and ENDKEYFUN are called. If STARTKEYFUN is nil, the key starts at the beginning of the record. ENDKEYFUN moves from the start of the sort key to the end of the sort key. ENDKEYFUN may be nil if STARTKEYFUN returns a value or if it would be the same as ENDRECFUN. PREDICATE is the function to use to compare keys. If keys are numbers, it defaults to `<', otherwise it defaults to `string<'. (defalias 'sort-subr #[(reverse nextrecfun endrecfun &optional startkeyfun endkeyfun predicate) "deZ\306V\212\203\307\310!\210\311 \n \f$\312 ! \203s\n\204+ \237\2033\307\313!\210\314 \203D\315\316\317BE\202[ @@\247\203O\320\202[ @@:\203Z\321\202[\322\"\n\203e \237\203m\307\323!\210\324 \"\210+\203|\307\325!\210*\326\207" [messages nextrecfun endrecfun startkeyfun endkeyfun sort-lists 50000 message "Finding sort keys..." sort-build-lists reverse "Sorting records..." sort lambda (a b) ((car a) (car b)) car-less-than-car #[(a b) "\302\303\304@@@A\304 @@ @A&V\207" [a b 0 compare-buffer-substrings nil] 8] #[(a b) "@ @\231\207" [a b] 2] "Reordering buffer..." sort-reorder-buffer "Reordering buffer... Done" nil old sort-fold-case case-fold-search predicate] 6 (#$ . 799)]) (defalias 'sort-build-lists #[(nextrecfun endrecfun startkeyfun endkeyfun) "\306\211\211\211m\204``\306\300\307\215 \306\204-\f\203$\f \210\202- \203- \210\310\203R:\203J@\n\232\203JA`\232\203J\211B\202O\n`BB B \204 \203 \210\202 ,\207" [key done start-rec sort-lists endrecfun nextrecfun nil (byte-code "\203  \206`\n\206 \305 \210 `)B\207" [startkeyfun start endkeyfun endrecfun done t] 2) t] 4]) (defalias 'sort-reorder-buffer #[(sort-lists old) "eedp\306\307\310!\311\216r q\210p\f\203Ldb\210\312 \f @A@#\210db\210\312 \f@A@\f@AA#\210 @AA\fA\f A \202db\210\312 \f\n#\210 q\210\313 \nS|\210eb\210\312!\210\n\211T|. \207" [temp-buffer old-buffer max min last #1=#:temp-buffer nil generate-new-buffer " *temp*" ((byte-code "\301!\203\n\302!\210\301\207" [#1# buffer-name kill-buffer] 2)) insert-buffer-substring t sort-lists old inhibit-quit] 5]) #@279 Sort lines in region alphabetically; argument means descending order. Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort). The variable `sort-fold-case' determines whether alphabetic case affects the sort order. (defalias 'sort-lines #[(reverse beg end) "\212\214 }\210eb\210\304\305 \306\307#+\207" [beg end inhibit-field-text-motion reverse t sort-subr forward-line end-of-line] 4 (#$ . 4262) "P\nr"]) #@284 Sort paragraphs in region alphabetically; argument means descending order. Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort). The variable `sort-fold-case' determines whether alphabetic case affects the sort order. (defalias 'sort-paragraphs #[(reverse beg end) "\212\214 }\210eb\210\303\n\304\305#*\207" [beg end reverse sort-subr #[nil "m?\205\301!\205\302y\210\202\207" [paragraph-separate looking-at 1] 2] forward-paragraph] 4 (#$ . 4741) "P\nr"]) #@279 Sort pages in region alphabetically; argument means descending order. Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort). The variable `sort-fold-case' determines whether alphabetic case affects the sort order. (defalias 'sort-pages #[(reverse beg end) "\212\214 }\210eb\210\303\n\304\305#*\207" [beg end reverse sort-subr #[nil "\300\301w\207" ["\n" nil] 2] forward-page] 4 (#$ . 5276) "P\nr"]) (byte-code "\301B\304\301!\204\305\301\306\"\210 \204F\307 \310\n\311W\203+\312\n\313 #\210\nT\211\202\312\314\315 #\210\312\316\315 #\210\312\317\315 #\210\312\320\321 #\210 *\306\207" [current-load-list sort-fields-syntax-table i table default-boundp set-default nil make-syntax-table 0 256 modify-syntax-entry "w" 32 " " 9 10 46 "_"] 5) #@50 *The default base used by `sort-numeric-fields'. (custom-declare-variable 'sort-numeric-base '10 '(#$ . -6098) :group 'sort :type 'integer) #@505 Sort lines in region numerically by the ARGth field of each line. Fields are separated by whitespace and numbered from 1 up. Specified field must contain a number in each line of the region, which may begin with "0x" or "0" for hexadecimal and octal values. Otherwise, the number is interpreted according to sort-numeric-base. With a negative arg, sorts by the ARGth field counted from the right. Called from a program, there are three arguments: FIELD, BEG and END. BEG and END specify region to sort. (defalias 'sort-numeric-fields #[(field beg end) "\304\305 \n \306\307%)\207" [inhibit-field-text-motion field beg end t sort-fields-1 #[nil "\304!\210\305\306\307!\205'\310\224\203\310\225b\210\311\202'\312\224\203&\312\225b\210\313\202'\314\315`\212\316\310!\210`){\n\2067 \"*\207" [field case-fold-search base sort-numeric-base sort-skip-fields t looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]" 1 16 2 8 nil string-to-number forward-sexp] 4] nil] 6 (#$ . 6245) "p\nr"]) #@398 Sort lines in region lexicographically by the ARGth field of each line. Fields are separated by whitespace and numbered from 1 up. With a negative arg, sorts by the ARGth field counted from the right. Called from a program, there are three arguments: FIELD, BEG and END. BEG and END specify region to sort. The variable `sort-fold-case' determines whether alphabetic case affects the sort order. (defalias 'sort-fields #[(field beg end) "\304\305 \n \306\307%)\207" [inhibit-field-text-motion field beg end t sort-fields-1 #[nil "\301!\210\302\207" [field sort-skip-fields nil] 2] #[nil "\300\301w\207" ["^ \n" nil] 2]] 6 (#$ . 7237) "p\nr"]) (defalias 'sort-fields-1 #[(field beg end startkeyfun endkeyfun) "\306 \307 !\203 \310\311\216\212\214\n }\210eb\210\312\f!\210\313\314\315\316 %,\207" [tbl field beg end sort-fields-syntax-table startkeyfun syntax-table zerop 1 ((set-syntax-table tbl)) set-syntax-table sort-subr nil forward-line end-of-line endkeyfun] 6]) (defalias 'sort-skip-fields #[(n) "\302V\2038S\211\302V\203\303\304w\210\305\304w\210 S\211\202\n\303\304w\210l\2056\306\307\212\310 \210`)\212\304\210`){\")\207\304\210[S\211\302V\203T\303\304x\210\305\304x\210 S\211\202@\303\304x\210)n\203n\306\307\212\310 \210`)\212\304\210`){\"\210\305\304x\207" [n i 0 " " nil "^ \n" error "Line has too few fields: %s" beginning-of-line] 5]) (defalias 'sort-regexp-fields-next-record #[nil "`\303 \304\305#\205.\306\225\211\205.\nU\203'\307u\210\303 \304\305#\210\306\225\211\202(\310\205.\306\224b)\207" [oldpos sort-regexp-fields-regexp sort-regexp-record-end re-search-forward nil move 0 1 t] 4]) #@907 Sort the region lexicographically as specified by RECORD-REGEXP and KEY. RECORD-REGEXP specifies the textual units which should be sorted. For example, to sort lines RECORD-REGEXP would be "^.*$" KEY specifies the part of each record (ie each match for RECORD-REGEXP) is to be used for sorting. If it is "\\digit" then the digit'th "\\(...\\)" match field from RECORD-REGEXP is used. If it is "\\&" then the whole record is used. Otherwise, it is a regular-expression for which to search within the record. If a match for KEY is not found within a record then that record is ignored. With a negative prefix arg sorts in reverse order. The variable `sort-fold-case' determines whether alphabetic case affects the sort order. For example: to sort lines in the region by the first word on each line starting with the letter "f", RECORD-REGEXP would be "^.*$" and KEY would be "\\=\" (defalias 'sort-regexp-fields #[(reverse record-regexp key-regexp beg end) "\306\232\204\f\307\232\203\310\202\311\312\"\203\313H\314Z\212\214 \n}\210eb\210\315 \316\f\315\317#\210`\310\224b\210\320\321\322\323$,\207" [key-regexp beg end record-regexp sort-regexp-fields-regexp sort-regexp-record-end "" "\\&" 0 string-match "\\`\\\\[1-9]\\'" 1 48 nil re-search-forward t sort-subr sort-regexp-fields-next-record #[nil "b\207" [sort-regexp-record-end] 1] #[nil "\303 \247\203\f \202\304 \n\305#\203\303\202\306\307\310\"\210\310\311\312\217)\207" [n key-regexp sort-regexp-record-end 0 re-search-forward t throw key nil (byte-code "\224\225B\207" [n] 2) ((error (byte-code "\300\301\302\"\207" [throw key nil] 3)))] 4] reverse] 5 (#$ . 8890) "P\nsRegexp specifying records to sort:\nsRegexp specifying key within record: \nr"]) (byte-code "\301B\302\301!\204\303\301\304\"\210\301\207" [current-load-list sort-columns-subprocess default-boundp set-default t] 3) #@719 Sort lines in region alphabetically by a certain range of columns. For the purpose of this command, the region BEG...END includes the entire line that point is in and the entire line the mark is in. The column positions of point and mark bound the range of columns to sort on. A prefix argument means sort into REVERSE order. The variable `sort-fold-case' determines whether alphabetic case affects the sort order. Note that `sort-columns' rejects text that contains tabs, because tabs could be split across the specified columns and it doesn't know how to handle that. Also, when possible, it uses the `sort' utility program, which doesn't understand tabs. Use \[untabify] to convert tabs to spaces before sorting. (defalias 'sort-columns #[(reverse &optional beg end) "\212\306\307\211\211\211\211\211^b\210i\310 \210`]b\210i\307y\210` \n^ \n]\311\312 \306#\203@\313\314!\210 \315>\204\206 \307\211!\"#\316\317\215+\204\206$\203`\320\202a\321\322\323 TT#D%&\203v\324%B%\325\326 \f\327\306\211\307%&)\202\230\212\214 \f}\210 b\210\330$\331\332\333\334%*.\207" [col-end col-start col-end1 col-beg1 end1 beg1 t nil beginning-of-line search-backward " " error "sort-columns does not work with tabs -- use M-x untabify" (vax-vms windows-nt) found (byte-code " W\205@\305!\306\n\303\"\n:\2036\n@\303=\204+\n@\307=\203& \204+\310\311\312\"\210\n\211AA)\211\202\313\314 #\211\202\207" [pos end1 plist fontified x text-properties-at plist-get face throw found t next-property-change nil] 5) "-rt " "-t " format "-k1.%d,1.%d" "-f" apply call-process-region "sort" sort-subr forward-line end-of-line #[nil "\301!\210\302\207" [col-start move-to-column nil] 2] #[nil "\301!\210\302\207" [col-end move-to-column nil] 2] inhibit-field-text-motion beg end system-type fontified plist pos reverse sort-args sort-fold-case] 9 (#$ . 10800) "P\nr"]) #@106 Reverse the order of lines in a region. From a program takes two point or marker arguments, BEG and END. (defalias 'reverse-region #[(beg end) " V\203\305 \n)\212b\210n\204\306y\210` b\210l\203'n\203-\307y\210\305\210\310 \305\311 \203Yb\210`\305\210`{\fB` U? \203S`T\202T`|\210\2024\fA\203k\f@\312\261\210\fA\211\202Z\f@c+\207" [beg end mid do ll nil 1 -1 point-marker t "\n"] 3 (#$ . 12704) "r"]) (provide 'sort)