1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-16 10:50:49 -08:00

Merge from emacs--devo--0

Patches applied:

 * emacs--devo--0  (patch 285-296)

   - Update from CVS
   - Merge from gnus--rel--5.10
   - Update from CVS: admin/FOR-RELEASE: Update refcard section.

 * gnus--rel--5.10  (patch 102-104)

   - Update from CVS

Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-64
This commit is contained in:
Miles Bader 2006-06-07 18:05:10 +00:00
commit b883cdb2fe
289 changed files with 27761 additions and 23242 deletions

View file

@ -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

View file

@ -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

View file

@ -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)))
(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)))))))
(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)))
;; 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))

View file

@ -171,8 +171,8 @@
;; | INTEGER_CONSTANT
;; | DEREF
;; DEREF ::= ( [NAME | INTEGER]... ) -- Field NAME or Array index relative to
;; current structure spec.
;; DEREF ::= ( [NAME | INTEGER]... ) -- Field NAME or Array index relative
;; to current structure spec.
;; -- see bindat-get-field
;; A `union' specification
@ -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,17 +404,19 @@ 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)))
((eq type 'repeat)
(let ((index 0))
(while (< index len)
(bindat--length-group (nth index (bindat-get-field struct field)) (nthcdr tail item))
(bindat--length-group
(nth index (bindat-get-field struct field))
(nthcdr tail item))
(setq index (1+ index)))))
((eq type 'union)
(let ((tag len) (cases (nthcdr tail item)) case cc)
@ -433,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 specification 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))
@ -462,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)
@ -479,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))
@ -511,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)
@ -547,17 +548,19 @@ 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)))
((eq type 'repeat)
(let ((index 0))
(while (< index len)
(bindat--pack-group (nth index (bindat-get-field struct field)) (nthcdr tail item))
(bindat--pack-group
(nth index (bindat-get-field struct field))
(nthcdr tail item))
(setq index (1+ index)))))
((eq type 'union)
(let ((tag len) (cases (nthcdr tail item)) case cc)
@ -575,17 +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 unpack 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

View file

@ -88,34 +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-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-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
;; ==================
@ -123,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)))
@ -177,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)
@ -205,45 +172,63 @@ 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 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
;; 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))))
(setq node (ewoc--node-right node))))))
(defun ewoc--insert-new-node (node data pretty-printer)
"Insert before NODE a new node for DATA, displayed by PRETTY-PRINTER.
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)
;; Insert the trailing newline using insert-before-markers
;; so that the start position for the next element is updated.
(insert-before-markers ?\n)
;; Move back, and call the pretty-printer.
(backward-char 1)
(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--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))
(let ((inhibit-read-only t)
(m (ewoc--node-start-marker node))
(R (ewoc--node-right node)))
;; First, remove the string from the buffer:
(delete-region (ewoc--node-start-marker node)
(1- (marker-position
(ewoc--node-start-marker (ewoc--node-right node)))))
(delete-region m (ewoc--node-start-marker R))
;; Calculate and insert the string.
(goto-char (ewoc--node-start-marker node))
(funcall pp (ewoc--node-data node))))
(goto-char m)
(funcall pp (ewoc--node-data node))
(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
(defun ewoc-create (pretty-printer &optional header footer)
;;;###autoload
(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.
@ -251,21 +236,25 @@ The ewoc will be inserted in the current buffer at the current position.
PRETTY-PRINTER should be a function that takes one argument, an
element, and inserts a string representing it in the buffer (at
point). The string PRETTY-PRINTER inserts may be empty or span
several lines. A trailing newline will always be inserted
automatically. The PRETTY-PRINTER should use `insert', and not
several lines. The PRETTY-PRINTER should use `insert', and not
`insert-before-markers'.
Optional second argument HEADER is a string that will always be
present at the top of the ewoc. HEADER should end with a
newline. Optional third argument FOOTER is similar, and will
be inserted at the bottom of the ewoc."
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.
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
@ -273,8 +262,9 @@ be inserted at the bottom 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
@ -285,6 +275,10 @@ be inserted at the bottom of the ewoc."
\(fn NODE)")
(defun ewoc-set-data (node data)
"Set NODE to encapsulate DATA."
(setf (ewoc--node-data node) data))
(defun ewoc-enter-first (ewoc data)
"Enter DATA first in EWOC.
Return the new node."
@ -297,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."
@ -322,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.
@ -352,13 +343,35 @@ If more than two arguments are given, the remaining
arguments will be passed to MAP-FUNCTION."
(ewoc--set-buffer-bind-dll-let* ewoc
((footer (ewoc--footer ewoc))
(pp (ewoc--pretty-printer ewoc))
(node (ewoc--node-nth dll 1)))
(save-excursion
(while (not (eq node footer))
(if (apply map-function (ewoc--node-data node) args)
(ewoc--refresh-node (ewoc--pretty-printer ewoc) 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) (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.
(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)
(setf L (ewoc--node-left node)
R (ewoc--node-right node)
;; Link neighbors to each other.
(ewoc--node-right L) R
(ewoc--node-left R) L
;; Forget neighbors.
(ewoc--node-left node) nil
(ewoc--node-right node) nil))))
(defun ewoc-filter (ewoc predicate &rest args)
"Remove all elements in EWOC for which PREDICATE returns nil.
Note that the buffer for EWOC will be current-buffer when PREDICATE
@ -369,28 +382,13 @@ ARGS are given they will be passed to the PREDICATE."
(ewoc--set-buffer-bind-dll-let* ewoc
((node (ewoc--node-nth dll 1))
(footer (ewoc--footer ewoc))
(next nil)
(L nil) (R nil)
(goodbye nil)
(inhibit-read-only t))
(while (not (eq node footer))
(setq next (ewoc--node-next dll node))
(unless (apply predicate (ewoc--node-data node) args)
;; 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))
(delete-region (ewoc--node-start-marker node)
(ewoc--node-start-marker (ewoc--node-next dll node)))
(set-marker (ewoc--node-start-marker node) nil)
(setf L (ewoc--node-left node)
R (ewoc--node-right node)
;; Link neighbors to each other.
(ewoc--node-right L) R
(ewoc--node-left R) L
;; Forget neighbors.
(ewoc--node-left node) nil
(ewoc--node-right node) nil))
(setq node next))))
(push node goodbye))
(setq node (ewoc--node-next dll node)))
(apply 'ewoc-delete ewoc goodbye)))
(defun ewoc-locate (ewoc &optional pos guess)
"Return the node that POS (a buffer position) is within.
@ -401,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?
@ -435,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)
@ -465,10 +462,11 @@ If the EWOC is empty, nil is returned."
(defun ewoc-invalidate (ewoc &rest nodes)
"Call EWOC's pretty-printer for each element in NODES.
Delete current text first, thus effecting a \"refresh\"."
(ewoc--set-buffer-bind-dll ewoc
(ewoc--set-buffer-bind-dll-let* ewoc
((pp (ewoc--pretty-printer ewoc)))
(save-excursion
(dolist (node nodes)
(ewoc--refresh-node (ewoc--pretty-printer ewoc) node)))))
(ewoc--refresh-node pp node dll)))))
(defun ewoc-goto-prev (ewoc arg)
"Move point to the ARGth previous element in EWOC.
@ -525,7 +523,6 @@ number of elements needs to be refreshed."
(while (not (eq node footer))
(set-marker (ewoc--node-start-marker node) (point))
(funcall pp (ewoc--node-data node))
(insert "\n")
(setq node (ewoc--node-next dll node)))))
(set-marker (ewoc--node-start-marker footer) (point))))
@ -564,19 +561,23 @@ Return nil if the buffer has been deleted."
(defun ewoc-set-hf (ewoc header footer)
"Set the HEADER and FOOTER of EWOC."
(setf (ewoc--node-data (ewoc--header ewoc)) header)
(setf (ewoc--node-data (ewoc--footer ewoc)) footer)
(save-excursion
(ewoc--refresh-node 'insert (ewoc--header ewoc))
(ewoc--refresh-node 'insert (ewoc--footer ewoc))))
(ewoc--set-buffer-bind-dll-let* ewoc
((head (ewoc--header 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 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