diff options
author | Karoly Lorentey <lorentey@elte.hu> | 2006-06-12 07:27:12 +0000 |
---|---|---|
committer | Karoly Lorentey <lorentey@elte.hu> | 2006-06-12 07:27:12 +0000 |
commit | 476e9367ec1f440aa23904b7bc482ea4a3b8041c (patch) | |
tree | 4f7f5a5e9a6668f908834bb6e216c8fa3727d4b3 /lisp/emacs-lisp | |
parent | a13f8f50d4cc544d3bbfa78568e82ce09e68bded (diff) | |
parent | 6b519504c3297595101628e823e72c91e562ab45 (diff) | |
download | emacs-476e9367ec1f440aa23904b7bc482ea4a3b8041c.tar.gz |
Merged from emacs@sv.gnu.org.
Patches applied:
* emacs@sv.gnu.org/emacs--devo--0--patch-294
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-295
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-296
Update from CVS: admin/FOR-RELEASE: Update refcard section.
* emacs@sv.gnu.org/emacs--devo--0--patch-297
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-298
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-299
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-300
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-301
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-302
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-303
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-304
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-103
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-104
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-570
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/advice.el | 3 | ||||
-rw-r--r-- | lisp/emacs-lisp/authors.el | 9 | ||||
-rw-r--r-- | lisp/emacs-lisp/autoload.el | 190 | ||||
-rw-r--r-- | lisp/emacs-lisp/bindat.el | 112 | ||||
-rw-r--r-- | lisp/emacs-lisp/ewoc.el | 172 |
5 files changed, 225 insertions, 261 deletions
diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el index 486a3b049ae..d03245bf452 100644 --- a/lisp/emacs-lisp/advice.el +++ b/lisp/emacs-lisp/advice.el @@ -2350,6 +2350,7 @@ FUNCTION was not advised)." (ad-advice-set-enabled advice flag)))))) matched-advices))) +;;;###autoload (defun ad-enable-advice (function class name) "Enables the advice of FUNCTION with CLASS and NAME." (interactive (ad-read-advice-specification "Enable advice of")) @@ -2359,6 +2360,7 @@ FUNCTION was not advised)." function class name)) (error "ad-enable-advice: `%s' is not advised" function))) +;;;###autoload (defun ad-disable-advice (function class name) "Disable the advice of FUNCTION with CLASS and NAME." (interactive (ad-read-advice-specification "Disable advice of")) @@ -3585,6 +3587,7 @@ the value of `ad-redefinition-action' and de/activate again." ;; @@ The top-level advice interface: ;; ================================== +;;;###autoload (defun ad-activate (function &optional compile) "Activate all the advice information of an advised FUNCTION. If FUNCTION has a proper original definition then an advised diff --git a/lisp/emacs-lisp/authors.el b/lisp/emacs-lisp/authors.el index 0d38ba03241..7ab0101b2a5 100644 --- a/lisp/emacs-lisp/authors.el +++ b/lisp/emacs-lisp/authors.el @@ -42,6 +42,7 @@ files.") (defconst authors-aliases '( + ("Andrew Csillag" "Drew Csillag") ("Barry A. Warsaw" "Barry A. Warsaw, Century Computing, Inc." "Barry A. Warsaw, ITB" "Barry Warsaw") ("Bj,Av(Brn Torkelsson" "Bjorn Torkelsson") @@ -118,6 +119,7 @@ files.") ("Roland B. Roberts" "Roland B Roberts" "Roland Roberts") ("Rui-Tao Dong" "Rui-Tao Dong ~{6-Hpln~}") ("Sam Steingold" "Sam Shteingold") + ("Satyaki Das" "Indexed search by Satyaki Das") ("Stefan Monnier" "Stefan") ("Stephen A. Wood" "(saw@cebaf.gov)") ("Steven L. Baur" "SL Baur" "Steven L Baur") @@ -128,6 +130,7 @@ files.") ("Torbj,Av(Brn Einarsson" "Torbj.*rn Einarsson") ("Toru Tomabechi" "Toru Tomabechi,") ("Vincent Del Vecchio" "Vince Del Vecchio") + ("William M. Perry" "Bill Perry") ("Wlodzimierz Bzyl" "W.*dek Bzyl") ("Yutaka NIIBE" "NIIBE Yutaka") ) @@ -269,7 +272,7 @@ Changes to files in this list are not listed.") ("Morten Welinder" :wrote "dosfns.c" "[many MSDOS files]" "msdos.h") ("Pace Willisson" :wrote "ispell.el") ("Garrett Wollman" :changed "sendmail.el") - ("Dale Worley" :changed "mail-extr.el") + ("Dale R. Worley" :changed "mail-extr.el") ("Jamie Zawinski" :changed "bytecode.c" :wrote "disass.el" "tar-mode.el")) "Actions taken from the original, manually (un)maintained AUTHORS file.") @@ -355,7 +358,9 @@ the file name." (setq rules (cdr rules)))))) (setq authors-checked-files-alist (cons (cons file valid) authors-checked-files-alist)) - (unless valid + (unless (or valid + (string-match "[*]" file) + (string-match "^[0-9.]+$" file)) (setq authors-invalid-file-names (cons (format "%s:%d: unrecognized `%s' for %s" log-file diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el index ee2d74c5646..76699f10df8 100644 --- a/lisp/emacs-lisp/autoload.el +++ b/lisp/emacs-lisp/autoload.el @@ -273,12 +273,30 @@ which lists the file name and which functions are in it, etc." (or (eolp) (insert "\n" generate-autoload-section-continuation)))))) +(defun autoload-find-file (file) + "Fetch file and put it in a temp buffer. Return the buffer." + ;; It is faster to avoid visiting the file. + (with-current-buffer (get-buffer-create " *autoload-file*") + (kill-all-local-variables) + (erase-buffer) + (setq buffer-undo-list t + buffer-read-only nil) + (emacs-lisp-mode) + (insert-file-contents file nil) + (let ((enable-local-variables :safe)) + (hack-local-variables)) + (current-buffer))) + +(defvar no-update-autoloads nil + "File local variable to prevent scanning this file for autoload cookies.") + (defun generate-file-autoloads (file) "Insert at point a loaddefs autoload section for FILE. -autoloads are generated for defuns and defmacros in FILE +Autoloads are generated for defuns and defmacros in FILE marked by `generate-autoload-cookie' (which see). If FILE is being visited in a buffer, the contents of the buffer -are used." +are used. +Return non-nil in the case where no autoloads were added at point." (interactive "fGenerate autoloads for file: ") (let ((outbuf (current-buffer)) (autoloads-done '()) @@ -291,7 +309,7 @@ are used." (float-output-format nil) (done-any nil) (visited (get-file-buffer file)) - output-end) + output-start) ;; If the autoload section we create here uses an absolute ;; file name for FILE in its header, and then Emacs is installed @@ -309,76 +327,70 @@ are used." (string= dir-truename (substring source-truename 0 len))) (setq file (substring source-truename len)))) - (message "Generating autoloads for %s..." file) - (save-excursion - (unwind-protect - (progn - (if visited - (set-buffer visited) - ;; It is faster to avoid visiting the file. - (set-buffer (get-buffer-create " *generate-autoload-file*")) - (kill-all-local-variables) - (erase-buffer) - (setq buffer-undo-list t - buffer-read-only nil) - (emacs-lisp-mode) - (insert-file-contents file nil)) - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (while (not (eobp)) - (skip-chars-forward " \t\n\f") - (cond - ((looking-at (regexp-quote generate-autoload-cookie)) - (search-forward generate-autoload-cookie) - (skip-chars-forward " \t") - (setq done-any t) - (if (eolp) - ;; Read the next form and make an autoload. - (let* ((form (prog1 (read (current-buffer)) - (or (bolp) (forward-line 1)))) - (autoload (make-autoload form load-name))) - (if autoload - (setq autoloads-done (cons (nth 1 form) - autoloads-done)) - (setq autoload form)) - (let ((autoload-print-form-outbuf outbuf)) - (autoload-print-form autoload))) - - ;; Copy the rest of the line to the output. - (princ (buffer-substring - (progn - ;; Back up over whitespace, to preserve it. - (skip-chars-backward " \f\t") - (if (= (char-after (1+ (point))) ? ) - ;; Eat one space. - (forward-char 1)) - (point)) - (progn (forward-line 1) (point))) - outbuf))) - ((looking-at ";") - ;; Don't read the comment. - (forward-line 1)) - (t - (forward-sexp 1) - (forward-line 1))))))) - (or visited - ;; We created this buffer, so we should kill it. - (kill-buffer (current-buffer))) - (set-buffer outbuf) - (setq output-end (point-marker)))) - (if done-any - (progn - ;; Insert the section-header line - ;; which lists the file name and which functions are in it, etc. - (autoload-insert-section-header outbuf autoloads-done load-name file - (nth 5 (file-attributes file))) - (insert ";;; Generated autoloads from " - (autoload-trim-file-name file) "\n") - (goto-char output-end) - (insert generate-autoload-section-trailer))) - (message "Generating autoloads for %s...done" file))) + (with-current-buffer (or visited + ;; It is faster to avoid visiting the file. + (autoload-find-file file)) + ;; Obey the no-update-autoloads file local variable. + (unless no-update-autoloads + (message "Generating autoloads for %s..." file) + (setq output-start (with-current-buffer outbuf (point))) + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (while (not (eobp)) + (skip-chars-forward " \t\n\f") + (cond + ((looking-at (regexp-quote generate-autoload-cookie)) + (search-forward generate-autoload-cookie) + (skip-chars-forward " \t") + (setq done-any t) + (if (eolp) + ;; Read the next form and make an autoload. + (let* ((form (prog1 (read (current-buffer)) + (or (bolp) (forward-line 1)))) + (autoload (make-autoload form load-name))) + (if autoload + (push (nth 1 form) autoloads-done) + (setq autoload form)) + (let ((autoload-print-form-outbuf outbuf)) + (autoload-print-form autoload))) + + ;; Copy the rest of the line to the output. + (princ (buffer-substring + (progn + ;; Back up over whitespace, to preserve it. + (skip-chars-backward " \f\t") + (if (= (char-after (1+ (point))) ? ) + ;; Eat one space. + (forward-char 1)) + (point)) + (progn (forward-line 1) (point))) + outbuf))) + ((looking-at ";") + ;; Don't read the comment. + (forward-line 1)) + (t + (forward-sexp 1) + (forward-line 1)))))) + + (when done-any + (with-current-buffer outbuf + (save-excursion + ;; Insert the section-header line which lists the file name + ;; and which functions are in it, etc. + (goto-char output-start) + (autoload-insert-section-header + outbuf autoloads-done load-name file + (nth 5 (file-attributes file))) + (insert ";;; Generated autoloads from " + (autoload-trim-file-name file) "\n")) + (insert generate-autoload-section-trailer))) + (message "Generating autoloads for %s...done" file)) + (or visited + ;; We created this buffer, so we should kill it. + (kill-buffer (current-buffer)))) + (not done-any))) ;;;###autoload (defun update-file-autoloads (file &optional save-after) @@ -457,37 +469,7 @@ Autoload section for %s is up to date." (goto-char (point-max)) (search-backward "\f" nil t))) (or (eq found 'up-to-date) - (and (eq found 'new) - ;; Check that FILE has any cookies before generating a - ;; new section for it. - (save-excursion - (if existing-buffer - (set-buffer existing-buffer) - ;; It is faster to avoid visiting the file. - (set-buffer (get-buffer-create " *autoload-file*")) - (kill-all-local-variables) - (erase-buffer) - (setq buffer-undo-list t - buffer-read-only nil) - (emacs-lisp-mode) - (insert-file-contents file nil)) - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (prog1 - (if (re-search-forward - (concat "^" (regexp-quote - generate-autoload-cookie)) - nil t) - nil - (if (interactive-p) - (message "%s has no autoloads" file)) - (setq no-autoloads t) - t) - (or existing-buffer - (kill-buffer (current-buffer)))))))) - (generate-file-autoloads file)))) + (setq no-autoloads (generate-file-autoloads file))))) (and save-after (buffer-modified-p) (save-buffer)) diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index 823fcf869b6..d05eed2c4a2 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -188,23 +188,20 @@ ;; ([FIELD] eval FORM) ;; is interpreted by evalling FORM for its side effects only. ;; If FIELD is specified, the value is bound to that field. -;; The FORM may access and update `raw-data' and `pos' (see `bindat-unpack'), -;; as well as the lisp data structure in `struct'. +;; The FORM may access and update `bindat-raw' and `bindat-idx' (see `bindat-unpack'). ;;; Code: ;; Helper functions for structure unpacking. -;; Relies on dynamic binding of RAW-DATA and POS +;; Relies on dynamic binding of BINDAT-RAW and BINDAT-IDX -(defvar raw-data) -(defvar pos) +(defvar bindat-raw) +(defvar bindat-idx) (defun bindat--unpack-u8 () (prog1 - (if (stringp raw-data) - (string-to-char (substring raw-data pos (1+ pos))) - (aref raw-data pos)) - (setq pos (1+ pos)))) + (aref bindat-raw bindat-idx) + (setq bindat-idx (1+ bindat-idx)))) (defun bindat--unpack-u16 () (let* ((a (bindat--unpack-u8)) (b (bindat--unpack-u8))) @@ -261,16 +258,16 @@ j (lsh j -1))))) bits)) ((eq type 'str) - (let ((s (substring raw-data pos (+ pos len)))) - (setq pos (+ pos len)) + (let ((s (substring bindat-raw bindat-idx (+ bindat-idx len)))) + (setq bindat-idx (+ bindat-idx len)) (if (stringp s) s (string-make-unibyte (concat s))))) ((eq type 'strz) (let ((i 0) s) - (while (and (< i len) (/= (aref raw-data (+ pos i)) 0)) + (while (and (< i len) (/= (aref bindat-raw (+ bindat-idx i)) 0)) (setq i (1+ i))) - (setq s (substring raw-data pos (+ pos i))) - (setq pos (+ pos len)) + (setq s (substring bindat-raw bindat-idx (+ bindat-idx i))) + (setq bindat-idx (+ bindat-idx len)) (if (stringp s) s (string-make-unibyte (concat s))))) ((eq type 'vec) @@ -312,10 +309,10 @@ (setq data (eval len)) (eval len))) ((eq type 'fill) - (setq pos (+ pos len))) + (setq bindat-idx (+ bindat-idx len))) ((eq type 'align) - (while (/= (% pos len) 0) - (setq pos (1+ pos)))) + (while (/= (% bindat-idx len) 0) + (setq bindat-idx (1+ bindat-idx)))) ((eq type 'struct) (setq data (bindat--unpack-group (eval len)))) ((eq type 'repeat) @@ -343,11 +340,13 @@ (setq struct (append data struct)))))) struct)) -(defun bindat-unpack (spec raw-data &optional pos) - "Return structured data according to SPEC for binary data in RAW-DATA. -RAW-DATA is a string or vector. Optional third arg POS specifies the -starting offset in RAW-DATA." - (unless pos (setq pos 0)) +(defun bindat-unpack (spec bindat-raw &optional bindat-idx) + "Return structured data according to SPEC for binary data in BINDAT-RAW. +BINDAT-RAW is a unibyte string or vector. Optional third arg BINDAT-IDX specifies +the starting offset in BINDAT-RAW." + (when (multibyte-string-p bindat-raw) + (error "String is multibyte")) + (unless bindat-idx (setq bindat-idx 0)) (bindat--unpack-group spec)) (defun bindat-get-field (struct &rest field) @@ -366,7 +365,7 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." struct) -;; Calculate raw-data length of structured data +;; Calculate bindat-raw length of structured data (defvar bindat--fixed-length-alist '((u8 . 1) (byte . 1) @@ -405,10 +404,10 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (setq struct (cons (cons field (eval len)) struct)) (eval len))) ((eq type 'fill) - (setq pos (+ pos len))) + (setq bindat-idx (+ bindat-idx len))) ((eq type 'align) - (while (/= (% pos len) 0) - (setq pos (1+ pos)))) + (while (/= (% bindat-idx len) 0) + (setq bindat-idx (1+ bindat-idx)))) ((eq type 'struct) (bindat--length-group (if field (bindat-get-field struct field) struct) (eval len))) @@ -435,25 +434,25 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (setq len (cdr type))) (if field (setq last (bindat-get-field struct field))) - (setq pos (+ pos len)))))))) + (setq bindat-idx (+ bindat-idx len)))))))) (defun bindat-length (spec struct) - "Calculate raw-data length for STRUCT according to bindat SPEC." - (let ((pos 0)) + "Calculate bindat-raw length for STRUCT according to bindat SPEC." + (let ((bindat-idx 0)) (bindat--length-group struct spec) - pos)) + bindat-idx)) -;; Pack structured data into raw-data +;; Pack structured data into bindat-raw (defun bindat--pack-u8 (v) - (aset raw-data pos (logand v 255)) - (setq pos (1+ pos))) + (aset bindat-raw bindat-idx (logand v 255)) + (setq bindat-idx (1+ bindat-idx))) (defun bindat--pack-u16 (v) - (aset raw-data pos (logand (lsh v -8) 255)) - (aset raw-data (1+ pos) (logand v 255)) - (setq pos (+ pos 2))) + (aset bindat-raw bindat-idx (logand (lsh v -8) 255)) + (aset bindat-raw (1+ bindat-idx) (logand v 255)) + (setq bindat-idx (+ bindat-idx 2))) (defun bindat--pack-u24 (v) (bindat--pack-u8 (lsh v -16)) @@ -464,9 +463,9 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (bindat--pack-u16 v)) (defun bindat--pack-u16r (v) - (aset raw-data (1+ pos) (logand (lsh v -8) 255)) - (aset raw-data pos (logand v 255)) - (setq pos (+ pos 2))) + (aset bindat-raw (1+ bindat-idx) (logand (lsh v -8) 255)) + (aset bindat-raw bindat-idx (logand v 255)) + (setq bindat-idx (+ bindat-idx 2))) (defun bindat--pack-u24r (v) (bindat--pack-u16r v) @@ -481,7 +480,7 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (setq type 'vec len 4)) (cond ((null v) - (setq pos (+ pos len))) + (setq bindat-idx (+ bindat-idx len))) ((memq type '(u8 byte)) (bindat--pack-u8 v)) ((memq type '(u16 word short)) @@ -513,11 +512,11 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (let ((l (length v)) (i 0)) (if (> l len) (setq l len)) (while (< i l) - (aset raw-data (+ pos i) (aref v i)) + (aset bindat-raw (+ bindat-idx i) (aref v i)) (setq i (1+ i))) - (setq pos (+ pos len)))) + (setq bindat-idx (+ bindat-idx len)))) (t - (setq pos (+ pos len))))) + (setq bindat-idx (+ bindat-idx len))))) (defun bindat--pack-group (struct spec) (let (last) @@ -549,10 +548,10 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (setq struct (cons (cons field (eval len)) struct)) (eval len))) ((eq type 'fill) - (setq pos (+ pos len))) + (setq bindat-idx (+ bindat-idx len))) ((eq type 'align) - (while (/= (% pos len) 0) - (setq pos (1+ pos)))) + (while (/= (% bindat-idx len) 0) + (setq bindat-idx (1+ bindat-idx)))) ((eq type 'struct) (bindat--pack-group (if field (bindat-get-field struct field) struct) (eval len))) @@ -579,18 +578,19 @@ e.g. corresponding to STRUCT.FIELD1[INDEX2].FIELD3..." (bindat--pack-item last type len) )))))) -(defun bindat-pack (spec struct &optional raw-data pos) +(defun bindat-pack (spec struct &optional bindat-raw bindat-idx) "Return binary data packed according to SPEC for structured data STRUCT. -Optional third arg RAW-DATA is a pre-allocated string or vector to pack into. -Optional fourth arg POS is the starting offset into RAW-DATA. -Note: The result is a multibyte string; use `string-make-unibyte' on it -to make it unibyte if necessary." - (let ((no-return raw-data)) - (unless pos (setq pos 0)) - (unless raw-data - (setq raw-data (make-vector (+ pos (bindat-length spec struct)) 0))) +Optional third arg BINDAT-RAW is a pre-allocated unibyte string or vector to +pack into. +Optional fourth arg BINDAT-IDX is the starting offset into BINDAT-RAW." + (when (multibyte-string-p bindat-raw) + (error "Pre-allocated string is multibyte")) + (let ((no-return bindat-raw)) + (unless bindat-idx (setq bindat-idx 0)) + (unless bindat-raw + (setq bindat-raw (make-vector (+ bindat-idx (bindat-length spec struct)) 0))) (bindat--pack-group struct spec) - (if no-return nil (concat raw-data)))) + (if no-return nil (concat bindat-raw)))) ;; Misc. format conversions diff --git a/lisp/emacs-lisp/ewoc.el b/lisp/emacs-lisp/ewoc.el index 2cb90738072..b4857f4310d 100644 --- a/lisp/emacs-lisp/ewoc.el +++ b/lisp/emacs-lisp/ewoc.el @@ -88,36 +88,7 @@ ;; limit! It is even possible to have another ewoc as an ;; element. In that way some kind of tree hierarchy can be created. ;; -;; Full documentation will, God willing, soon be available in a -;; Texinfo manual. - -;; In the mean time `grep '^(.*ewoc-[^-]' emacs-lisp/ewoc.el' can help -;; you find all the exported functions: -;; -;; (defun ewoc-create (pretty-printer &optional header footer) -;; (defalias 'ewoc-data 'ewoc--node-data) -;; (defun ewoc-set-data (node data) -;; (defun ewoc-location (node) -;; (defun ewoc-enter-first (ewoc data) -;; (defun ewoc-enter-last (ewoc data) -;; (defun ewoc-enter-after (ewoc node data) -;; (defun ewoc-enter-before (ewoc node data) -;; (defun ewoc-next (ewoc node) -;; (defun ewoc-prev (ewoc node) -;; (defun ewoc-nth (ewoc n) -;; (defun ewoc-map (map-function ewoc &rest args) -;; (defun ewoc-filter (ewoc predicate &rest args) -;; (defun ewoc-delete (ewoc &rest nodes) -;; (defun ewoc-locate (ewoc &optional pos guess) -;; (defun ewoc-invalidate (ewoc &rest nodes) -;; (defun ewoc-goto-prev (ewoc arg) -;; (defun ewoc-goto-next (ewoc arg) -;; (defun ewoc-goto-node (ewoc node) -;; (defun ewoc-refresh (ewoc) -;; (defun ewoc-collect (ewoc predicate &rest args) -;; (defun ewoc-buffer (ewoc) -;; (defun ewoc-get-hf (ewoc) -;; (defun ewoc-set-hf (ewoc header footer) +;; The Emacs Lisp Reference Manual documents ewoc.el's "public interface". ;; Coding conventions ;; ================== @@ -125,48 +96,43 @@ ;; All functions of course start with `ewoc'. Functions and macros ;; starting with the prefix `ewoc--' are meant for internal use, ;; while those starting with `ewoc-' are exported for public use. -;; There are currently no global or buffer-local variables used. - ;;; Code: -(eval-when-compile (require 'cl)) ;because of CL compiler macros - -;; The doubly linked list is implemented as a circular list -;; with a dummy node first and last. The dummy node is used as -;; "the dll" (or rather is the dll handle passed around). +(eval-when-compile (require 'cl)) +;; The doubly linked list is implemented as a circular list with a dummy +;; node first and last. The dummy node is used as "the dll". (defstruct (ewoc--node - (:type vector) ;required for ewoc--node-branch hack + (:type vector) ;ewoc--node-nth needs this + (:constructor nil) (:constructor ewoc--node-create (start-marker data))) left right data start-marker) -(defalias 'ewoc--node-branch 'aref - "Get the left (CHILD=0) or right (CHILD=1) child of the NODE. - -\(fn NODE CHILD)") - (defun ewoc--node-next (dll node) "Return the node after NODE, or nil if NODE is the last node." - (unless (eq (ewoc--node-right node) dll) (ewoc--node-right node))) + (let ((R (ewoc--node-right node))) + (unless (eq dll R) R))) (defun ewoc--node-prev (dll node) "Return the node before NODE, or nil if NODE is the first node." - (unless (eq (ewoc--node-left node) dll) (ewoc--node-left node))) + (let ((L (ewoc--node-left node))) + (unless (eq dll L) L))) (defun ewoc--node-nth (dll n) - "Return the Nth node from the doubly linked list DLL. -N counts from zero. If DLL is not that long, nil is returned. -If N is negative, return the -(N+1)th last element. + "Return the Nth node from the doubly linked list `dll'. +N counts from zero. If N is negative, return the -(N+1)th last element. +If N is out of range, return nil. Thus, (ewoc--node-nth dll 0) returns the first node, and (ewoc--node-nth dll -1) returns the last node." + ;; Presuming a node is ":type vector", starting with `left' and `right': ;; Branch 0 ("follow left pointer") is used when n is negative. ;; Branch 1 ("follow right pointer") is used otherwise. (let* ((branch (if (< n 0) 0 1)) - (node (ewoc--node-branch dll branch))) + (node (aref dll branch))) (if (< n 0) (setq n (- -1 n))) (while (and (not (eq dll node)) (> n 0)) - (setq node (ewoc--node-branch node branch)) + (setq node (aref node branch)) (setq n (1- n))) (unless (eq dll node) node))) @@ -179,16 +145,15 @@ and (ewoc--node-nth dll -1) returns the last node." (defstruct (ewoc (:constructor nil) - (:constructor ewoc--create - (buffer pretty-printer header footer dll)) + (:constructor ewoc--create (buffer pretty-printer dll)) (:conc-name ewoc--)) - buffer pretty-printer header footer dll last-node) + buffer pretty-printer header footer dll last-node hf-pp) (defmacro ewoc--set-buffer-bind-dll-let* (ewoc varlist &rest forms) "Execute FORMS with ewoc--buffer selected as current buffer, -dll bound to ewoc--dll, and VARLIST bound as in a let*. -dll will be bound when VARLIST is initialized, but the current -buffer will *not* have been changed. +`dll' bound to the dll, and VARLIST bound as in a let*. +`dll' will be bound when VARLIST is initialized, but +the current buffer will *not* have been changed. Return value of last form in FORMS." (let ((hnd (make-symbol "ewoc"))) `(let* ((,hnd ,ewoc) @@ -207,17 +172,20 @@ BUT if it is the header or the footer in EWOC return nil instead." (eq node (ewoc--footer ewoc))) node)) -(defun ewoc--adjust (beg end node) +(defun ewoc--adjust (beg end node dll) ;; "Manually reseat" markers for NODE and its successors (including footer ;; and dll), in the case where they originally shared start position with ;; BEG, to END. BEG and END are buffer positions describing NODE's left ;; neighbor. This operation is functionally equivalent to temporarily ;; setting these nodes' markers' insertion type to t around the pretty-print - ;; call that precedes the call to `ewoc-adjust', and then changing them back + ;; call that precedes the call to `ewoc--adjust', and then changing them back ;; to nil. (when (< beg end) (let (m) (while (and (= beg (setq m (ewoc--node-start-marker node))) + ;; The "dummy" node `dll' actually holds the marker that + ;; points to the end of the footer, so we check `dll' + ;; *after* reseating the marker. (progn (set-marker m end) (not (eq dll node)))) @@ -228,21 +196,16 @@ BUT if it is the header or the footer in EWOC return nil instead." Call PRETTY-PRINTER with point at NODE's start, thus pushing back NODE and leaving the new node's start there. Return the new node." (save-excursion - (let* ((inhibit-read-only t) - (m (copy-marker (ewoc--node-start-marker node))) - (pos (marker-position m)) - (elemnode (ewoc--node-create m data))) - (goto-char pos) - (funcall pretty-printer data) - (setf (marker-position m) pos - (ewoc--node-left elemnode) (ewoc--node-left node) + (let ((elemnode (ewoc--node-create + (copy-marker (ewoc--node-start-marker node)) data))) + (setf (ewoc--node-left elemnode) (ewoc--node-left node) (ewoc--node-right elemnode) node (ewoc--node-right (ewoc--node-left node)) elemnode (ewoc--node-left node) elemnode) - (ewoc--adjust pos (point) node) + (ewoc--refresh-node pretty-printer elemnode dll) elemnode))) -(defun ewoc--refresh-node (pp node) +(defun ewoc--refresh-node (pp node dll) "Redisplay the element represented by NODE using the pretty-printer PP." (let ((inhibit-read-only t) (m (ewoc--node-start-marker node)) @@ -252,13 +215,20 @@ NODE and leaving the new node's start there. Return the new node." ;; Calculate and insert the string. (goto-char m) (funcall pp (ewoc--node-data node)) - (ewoc--adjust m (point) R))) + (ewoc--adjust m (point) R dll))) + +(defun ewoc--wrap (func) + (lexical-let ((ewoc--user-pp func)) + (lambda (data) + (funcall ewoc--user-pp data) + (insert "\n")))) + ;;; =========================================================================== ;;; Public members of the Ewoc package ;;;###autoload -(defun ewoc-create (pretty-printer &optional header footer) +(defun ewoc-create (pretty-printer &optional header footer nosep) "Create an empty ewoc. The ewoc will be inserted in the current buffer at the current position. @@ -271,14 +241,20 @@ several lines. The PRETTY-PRINTER should use `insert', and not Optional second and third arguments HEADER and FOOTER are strings, possibly empty, that will always be present at the top and bottom, -respectively, of the ewoc." +respectively, of the ewoc. + +Normally, a newline is automatically inserted after the header, +the footer and every node's printed representation. Optional +fourth arg NOSEP non-nil inhibits this." (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST)) (dll (progn (setf (ewoc--node-right dummy-node) dummy-node) (setf (ewoc--node-left dummy-node) dummy-node) dummy-node)) - (new-ewoc - (ewoc--create (current-buffer) - pretty-printer nil nil dll)) + (wrap (if nosep 'identity 'ewoc--wrap)) + (new-ewoc (ewoc--create (current-buffer) + (funcall wrap pretty-printer) + dll)) + (hf-pp (funcall wrap 'insert)) (pos (point)) head foot) (ewoc--set-buffer-bind-dll new-ewoc @@ -286,8 +262,9 @@ respectively, of the ewoc." (unless header (setq header "")) (unless footer (setq footer "")) (setf (ewoc--node-start-marker dll) (copy-marker pos) - foot (ewoc--insert-new-node dll footer 'insert) - head (ewoc--insert-new-node foot header 'insert) + foot (ewoc--insert-new-node dll footer hf-pp) + head (ewoc--insert-new-node foot header hf-pp) + (ewoc--hf-pp new-ewoc) hf-pp (ewoc--footer new-ewoc) foot (ewoc--header new-ewoc) head)) ;; Return the ewoc @@ -314,7 +291,6 @@ Return the new node." (ewoc--set-buffer-bind-dll ewoc (ewoc-enter-before ewoc (ewoc--node-nth dll -1) data))) - (defun ewoc-enter-after (ewoc node data) "Enter a new element DATA after NODE in EWOC. Return the new node." @@ -339,21 +315,19 @@ Return nil if NODE is nil or the last element." Return nil if NODE is nil or the first element." (when node (ewoc--filter-hf-nodes - ewoc - (ewoc--node-prev (ewoc--dll ewoc) node)))) - + ewoc (ewoc--node-prev (ewoc--dll ewoc) node)))) (defun ewoc-nth (ewoc n) "Return the Nth node. N counts from zero. Return nil if there is less than N elements. If N is negative, return the -(N+1)th last element. -Thus, (ewoc-nth dll 0) returns the first node, -and (ewoc-nth dll -1) returns the last node. +Thus, (ewoc-nth ewoc 0) returns the first node, +and (ewoc-nth ewoc -1) returns the last node. Use `ewoc-data' to extract the data from the node." ;; Skip the header (or footer, if n is negative). (setq n (if (< n 0) (1- n) (1+ n))) (ewoc--filter-hf-nodes ewoc - (ewoc--node-nth (ewoc--dll ewoc) n))) + (ewoc--node-nth (ewoc--dll ewoc) n))) (defun ewoc-map (map-function ewoc &rest args) "Apply MAP-FUNCTION to all elements in EWOC. @@ -374,18 +348,18 @@ arguments will be passed to MAP-FUNCTION." (save-excursion (while (not (eq node footer)) (if (apply map-function (ewoc--node-data node) args) - (ewoc--refresh-node pp node)) + (ewoc--refresh-node pp node dll)) (setq node (ewoc--node-next dll node)))))) (defun ewoc-delete (ewoc &rest nodes) "Delete NODES from EWOC." (ewoc--set-buffer-bind-dll-let* ewoc - ((L nil) (R nil)) + ((L nil) (R nil) (last (ewoc--last-node ewoc))) (dolist (node nodes) ;; If we are about to delete the node pointed at by last-node, ;; set last-node to nil. - (if (eq (ewoc--last-node ewoc) node) - (setf (ewoc--last-node ewoc) nil)) + (when (eq last node) + (setf last nil (ewoc--last-node ewoc) nil)) (delete-region (ewoc--node-start-marker node) (ewoc--node-start-marker (ewoc--node-next dll node))) (set-marker (ewoc--node-start-marker node) nil) @@ -425,8 +399,7 @@ If POS points before the first element, the first node is returned. If POS points after the last element, the last node is returned. If the EWOC is empty, nil is returned." (unless pos (setq pos (point))) - (ewoc--set-buffer-bind-dll-let* ewoc - ((footer (ewoc--footer ewoc))) + (ewoc--set-buffer-bind-dll ewoc (cond ;; Nothing present? @@ -459,7 +432,7 @@ If the EWOC is empty, nil is returned." (setq distance d) (setq best-guess g))) - (when (ewoc--last-node ewoc) ;Check "previous". + (when (ewoc--last-node ewoc) ;Check "previous". (let* ((g (ewoc--last-node ewoc)) (d (abs (- pos (ewoc--node-start-marker g))))) (when (< d distance) @@ -493,7 +466,7 @@ Delete current text first, thus effecting a \"refresh\"." ((pp (ewoc--pretty-printer ewoc))) (save-excursion (dolist (node nodes) - (ewoc--refresh-node pp node))))) + (ewoc--refresh-node pp node dll))))) (defun ewoc-goto-prev (ewoc arg) "Move point to the ARGth previous element in EWOC. @@ -590,20 +563,21 @@ Return nil if the buffer has been deleted." "Set the HEADER and FOOTER of EWOC." (ewoc--set-buffer-bind-dll-let* ewoc ((head (ewoc--header ewoc)) - (foot (ewoc--footer ewoc))) + (foot (ewoc--footer ewoc)) + (hf-pp (ewoc--hf-pp ewoc))) (setf (ewoc--node-data head) header (ewoc--node-data foot) footer) (save-excursion - (ewoc--refresh-node 'insert head) - (ewoc--refresh-node 'insert foot)))) + (ewoc--refresh-node hf-pp head dll) + (ewoc--refresh-node hf-pp foot dll)))) (provide 'ewoc) -;;; Local Variables: -;;; eval: (put 'ewoc--set-buffer-bind-dll 'lisp-indent-hook 1) -;;; eval: (put 'ewoc--set-buffer-bind-dll-let* 'lisp-indent-hook 2) -;;; End: +;; Local Variables: +;; eval: (put 'ewoc--set-buffer-bind-dll 'lisp-indent-hook 1) +;; eval: (put 'ewoc--set-buffer-bind-dll-let* 'lisp-indent-hook 2) +;; End: -;;; arch-tag: d78915b9-9a07-44bf-aac6-04a1fc1bd6d4 +;; arch-tag: d78915b9-9a07-44bf-aac6-04a1fc1bd6d4 ;;; ewoc.el ends here |