Function: idlwave-routine-twin-compare
idlwave-routine-twin-compare is a byte-compiled function defined in
idlwave.el.gz.
Signature
(idlwave-routine-twin-compare A B)
Documentation
Compare two routine twin entries for sorting.
In here, A and B are not normal routine info entries, but special lists (KEY FILENAME (TYPES...)). This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/idlwave.el.gz
(defun idlwave-routine-twin-compare (a b)
"Compare two routine twin entries for sorting.
In here, A and B are not normal routine info entries, but special
lists (KEY FILENAME (TYPES...)).
This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values."
(let* (;; Dis-assemble entries
(akey (car a)) (bkey (car b))
(afile (nth 1 a)) (bfile (nth 1 b))
(atypes (nth 2 a)) (btypes (nth 2 b))
;; System routines?
(asysp (memq akey '(builtin system)))
(bsysp (memq bkey '(builtin system)))
;; Compiled routines?
(acompp (memq 'compiled atypes))
(bcompp (memq 'compiled btypes))
;; Unresolved?
(aunresp (or (eq akey 'unresolved)
(and acompp (not afile))))
(bunresp (or (eq bkey 'unresolved)
(and bcompp (not bfile))))
;; Buffer info available?
(abufp (memq 'buffer atypes))
(bbufp (memq 'buffer btypes))
;; On search path?
(tpath-alist (idlwave-true-path-alist))
(apathp (and (stringp akey)
(assoc (file-name-directory akey) tpath-alist)))
(bpathp (and (stringp bkey)
(assoc (file-name-directory bkey) tpath-alist)))
;; How early on search path? High number means early since we
;; measure the tail of the path list
(anpath (length (memq apathp tpath-alist)))
(bnpath (length (memq bpathp tpath-alist)))
;; Look at file names
(aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
(bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
(fname-re (if idlwave-twin-class
(format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
(regexp-quote (downcase idlwave-twin-class))
(regexp-quote (downcase idlwave-twin-name)))
(format "\\`%s\\.pro" (regexp-quote (downcase idlwave-twin-name)))))
;; Is file name derived from the routine name?
;; Method file or class definition file?
(anamep (string-match fname-re aname))
(adefp (and idlwave-twin-class anamep
(string= "define" (match-string 1 aname))))
(bnamep (string-match fname-re bname))
(bdefp (and idlwave-twin-class bnamep
(string= "define" (match-string 1 bname)))))
;; Now: follow JD's ideas about sorting. Looks really simple now,
;; doesn't it? The difficult stuff is hidden above...
(cond
((xor asysp bsysp) asysp) ; System entries first
((xor aunresp bunresp) bunresp) ; Unresolved last
((and idlwave-sort-prefer-buffer-info
(xor abufp bbufp)) abufp) ; Buffers before non-buffers
((xor acompp bcompp) acompp) ; Compiled entries
((xor apathp bpathp) apathp) ; Library before non-library
((xor anamep bnamep) anamep) ; Correct file names first
((and idlwave-twin-class anamep bnamep ; both file names match ->
(xor adefp bdefp)) bdefp) ; __define after __method
((> anpath bnpath) t) ; Who is first on path?
(t nil)))) ; Default