1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

* lisp/subr.el (with-wrapper-hook): Declare obsolete.

* lisp/simple.el (filter-buffer-substring-function): New hook.
(filter-buffer-substring): Use it.
(filter-buffer-substring-functions): Mark obsolete.
* lisp/minibuffer.el (completion-in-region-function): New hook.
(completion-in-region): Use it.
(completion-in-region-functions): Mark obsolete.
* lisp/mail/mailabbrev.el (mail-abbrevs-setup): Use abbrev-expand-function.
* lisp/abbrev.el (abbrev-expand-function): New hook.
(expand-abbrev): Use it.
(abbrev-expand-functions): Mark obsolete.
* lisp/emacs-lisp/nadvice.el (advice--where-alist): Add :filter-args
and :filter-return.
* lisp/org/org-agenda.el (org-agenda-mode):
* lisp/org/org-indent.el (org-indent-mode): Use the `local' arg of
add-hook/remove-hook.
This commit is contained in:
Stefan Monnier 2013-04-17 20:12:33 -04:00
parent 04754d3612
commit d36ed1c8e7
11 changed files with 709 additions and 674 deletions

View file

@ -329,6 +329,13 @@ file using `set-file-extended-attributes'.
*** `field-complete' *** `field-complete'
*** `minibuffer-completion-contents' *** `minibuffer-completion-contents'
** `with-wrapper-hook' is obsoleted by `add-function'.
The few hooks that used with-wrapper-hook are replaced as follows:
*** `abbrev-expand-function' obsoletes `abbrev-expand-functions'.
*** `completion-in-region-function' obsoletes `completion-in-region-functions'.
*** `filter-buffer-substring-function' obsoletes `filter-buffer-substring-functions'.
** `get-upcase-table' is obsoleted by the new `case-table-get-table'. ** `get-upcase-table' is obsoleted by the new `case-table-get-table'.
** Support for filesystem notifications. ** Support for filesystem notifications.

View file

@ -1,3 +1,19 @@
2013-04-18 Stefan Monnier <monnier@iro.umontreal.ca>
* subr.el (with-wrapper-hook): Declare obsolete.
* simple.el (filter-buffer-substring-function): New hook.
(filter-buffer-substring): Use it.
(filter-buffer-substring-functions): Mark obsolete.
* minibuffer.el (completion-in-region-function): New hook.
(completion-in-region): Use it.
(completion-in-region-functions): Mark obsolete.
* mail/mailabbrev.el (mail-abbrevs-setup): Use abbrev-expand-function.
* abbrev.el (abbrev-expand-function): New hook.
(expand-abbrev): Use it.
(abbrev-expand-functions): Mark obsolete.
* emacs-lisp/nadvice.el (advice--where-alist): Add :filter-args
and :filter-return.
2013-04-17 Fabián Ezequiel Gallina <fgallina@gnu.org> 2013-04-17 Fabián Ezequiel Gallina <fgallina@gnu.org>
* progmodes/python.el (python-nav--syntactically): Fix cornercases * progmodes/python.el (python-nav--syntactically): Fix cornercases

View file

@ -532,7 +532,7 @@ This is the first thing that `expand-abbrev' does, and so this may change
the current abbrev table before abbrev lookup happens." the current abbrev table before abbrev lookup happens."
:type 'hook :type 'hook
:group 'abbrev-mode) :group 'abbrev-mode)
(make-obsolete-variable 'pre-abbrev-expand-hook 'abbrev-expand-functions "23.1") (make-obsolete-variable 'pre-abbrev-expand-hook 'abbrev-expand-function "23.1")
(defun clear-abbrev-table (table) (defun clear-abbrev-table (table)
"Undefine all abbrevs in abbrev table TABLE, leaving it empty." "Undefine all abbrevs in abbrev table TABLE, leaving it empty."
@ -832,10 +832,12 @@ see `define-abbrev' for details."
value)) value))
(defvar abbrev-expand-functions nil (defvar abbrev-expand-functions nil
"Wrapper hook around `expand-abbrev'. "Wrapper hook around `expand-abbrev'.")
The functions on this special hook are called with one argument: (make-obsolete-variable 'abbrev-expand-functions 'abbrev-expand-function "24.4")
a function that performs the abbrev expansion. It should return
the abbrev symbol if expansion took place.") (defvar abbrev-expand-function #'abbrev--default-expand
"Function to perform abbrev expansion.
Takes no argument and should return the abbrev symbol if expansion took place.")
(defun expand-abbrev () (defun expand-abbrev ()
"Expand the abbrev before point, if there is an abbrev there. "Expand the abbrev before point, if there is an abbrev there.
@ -844,6 +846,9 @@ Returns the abbrev symbol, if expansion took place. (The actual
return value is that of `abbrev-insert'.)" return value is that of `abbrev-insert'.)"
(interactive) (interactive)
(run-hooks 'pre-abbrev-expand-hook) (run-hooks 'pre-abbrev-expand-hook)
(funcall abbrev-expand-function))
(defun abbrev--default-expand ()
(with-wrapper-hook abbrev-expand-functions () (with-wrapper-hook abbrev-expand-functions ()
(pcase-let ((`(,sym ,name ,wordstart ,wordend) (abbrev--before-point))) (pcase-let ((`(,sym ,name ,wordstart ,wordend) (abbrev--before-point)))
(when sym (when sym

View file

@ -44,7 +44,9 @@
(:after-until "\300\302\002\"\206\013\000\300\301\002\"\207" 4) (:after-until "\300\302\002\"\206\013\000\300\301\002\"\207" 4)
(:after-while "\300\302\002\"\205\013\000\300\301\002\"\207" 4) (:after-while "\300\302\002\"\205\013\000\300\301\002\"\207" 4)
(:before-until "\300\301\002\"\206\013\000\300\302\002\"\207" 4) (:before-until "\300\301\002\"\206\013\000\300\302\002\"\207" 4)
(:before-while "\300\301\002\"\205\013\000\300\302\002\"\207" 4)) (:before-while "\300\301\002\"\205\013\000\300\302\002\"\207" 4)
(:filter-args "\300\302\301!\"\207" 5)
(:filter-return "\301\300\302\"!\207" 5))
"List of descriptions of how to add a function. "List of descriptions of how to add a function.
Each element has the form (WHERE BYTECODE STACK) where: Each element has the form (WHERE BYTECODE STACK) where:
WHERE is a keyword indicating where the function is added. WHERE is a keyword indicating where the function is added.
@ -208,7 +210,6 @@ WHERE is a symbol to select an entry in `advice--where-alist'."
;;;###autoload ;;;###autoload
(defmacro add-function (where place function &optional props) (defmacro add-function (where place function &optional props)
;; TODO: ;; TODO:
;; - obsolete with-wrapper-hook (mostly requires buffer-local support).
;; - provide some kind of control over ordering. E.g. debug-on-entry, ELP ;; - provide some kind of control over ordering. E.g. debug-on-entry, ELP
;; and tracing want to stay first. ;; and tracing want to stay first.
;; - maybe let `where' specify some kind of predicate and use it ;; - maybe let `where' specify some kind of predicate and use it
@ -231,6 +232,8 @@ call OLDFUN here:
`:before-until' (lambda (&rest r) (or (apply FUNCTION r) (apply OLDFUN r))) `:before-until' (lambda (&rest r) (or (apply FUNCTION r) (apply OLDFUN r)))
`:after-while' (lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r))) `:after-while' (lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r)))
`:after-until' (lambda (&rest r) (or (apply OLDFUN r) (apply FUNCTION r))) `:after-until' (lambda (&rest r) (or (apply OLDFUN r) (apply FUNCTION r)))
`:filter-args' (lambda (&rest r) (apply OLDFUN (funcall FUNCTION r)))
`:filter-return'(lambda (&rest r) (funcall FUNCTION (apply OLDFUN r)))
If FUNCTION was already added, do nothing. If FUNCTION was already added, do nothing.
PROPS is an alist of additional properties, among which the following have PROPS is an alist of additional properties, among which the following have
a special meaning: a special meaning:

View file

@ -182,7 +182,8 @@ no aliases, which is represented by this being a table with no entries.)")
(nth 5 (file-attributes mail-personal-alias-file))) (nth 5 (file-attributes mail-personal-alias-file)))
(build-mail-abbrevs))) (build-mail-abbrevs)))
(mail-abbrevs-sync-aliases) (mail-abbrevs-sync-aliases)
(add-hook 'abbrev-expand-functions 'mail-abbrev-expand-wrapper nil t) (add-function :around (local 'abbrev-expand-function)
#'mail-abbrev-expand-wrapper)
(abbrev-mode 1)) (abbrev-mode 1))
(defun mail-abbrevs-enable () (defun mail-abbrevs-enable ()

View file

@ -1764,14 +1764,15 @@ variables.")
(exit-minibuffer)) (exit-minibuffer))
(defvar completion-in-region-functions nil (defvar completion-in-region-functions nil
"Wrapper hook around `completion-in-region'. "Wrapper hook around `completion-in-region'.")
The functions on this special hook are called with 5 arguments: (make-obsolete-variable 'completion-in-region-functions
NEXT-FUN START END COLLECTION PREDICATE. 'completion-in-region-function "24.4")
NEXT-FUN is a function of four arguments (START END COLLECTION PREDICATE)
that performs the default operation. The other four arguments are like (defvar completion-in-region-function #'completion--in-region
the ones passed to `completion-in-region'. The functions on this hook "Function to perform the job of `completion-in-region'.
are expected to perform completion on START..END using COLLECTION The function is called with 4 arguments: START END COLLECTION PREDICATE.
and PREDICATE, either by calling NEXT-FUN or by doing it themselves.") The arguments and expected return value are like the ones of
`completion-in-region'.")
(defvar completion-in-region--data nil) (defvar completion-in-region--data nil)
@ -1793,6 +1794,9 @@ Point needs to be somewhere between START and END.
PREDICATE (a function called with no arguments) says when to PREDICATE (a function called with no arguments) says when to
exit." exit."
(cl-assert (<= start (point)) (<= (point) end)) (cl-assert (<= start (point)) (<= (point) end))
(funcall completion-in-region-function start end collection predicate))
(defun completion--in-region (start end collection &optional predicate)
(with-wrapper-hook (with-wrapper-hook
;; FIXME: Maybe we should use this hook to provide a "display ;; FIXME: Maybe we should use this hook to provide a "display
;; completions" operation as well. ;; completions" operation as well.

File diff suppressed because it is too large Load diff

View file

@ -2015,10 +2015,10 @@ The following commands are available:
(org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local) (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
(org-add-hook 'pre-command-hook 'org-unhighlight nil 'local) (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
;; Make sure properties are removed when copying text ;; Make sure properties are removed when copying text
(make-local-variable 'filter-buffer-substring-functions)
(add-hook 'filter-buffer-substring-functions (add-hook 'filter-buffer-substring-functions
(lambda (fun start end delete) (lambda (fun start end delete)
(substring-no-properties (funcall fun start end delete)))) (substring-no-properties (funcall fun start end delete)))
nil t)
(unless org-agenda-keep-modes (unless org-agenda-keep-modes
(setq org-agenda-follow-mode org-agenda-start-with-follow-mode (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode

View file

@ -182,11 +182,11 @@ during idle time."
(org-set-local 'org-hide-leading-stars-before-indent-mode (org-set-local 'org-hide-leading-stars-before-indent-mode
org-hide-leading-stars) org-hide-leading-stars)
(org-set-local 'org-hide-leading-stars t)) (org-set-local 'org-hide-leading-stars t))
(make-local-variable 'filter-buffer-substring-functions)
(add-hook 'filter-buffer-substring-functions (add-hook 'filter-buffer-substring-functions
(lambda (fun start end delete) (lambda (fun start end delete)
(org-indent-remove-properties-from-string (org-indent-remove-properties-from-string
(funcall fun start end delete)))) (funcall fun start end delete)))
nil t)
(org-add-hook 'after-change-functions 'org-indent-refresh-maybe nil 'local) (org-add-hook 'after-change-functions 'org-indent-refresh-maybe nil 'local)
(org-add-hook 'before-change-functions (org-add-hook 'before-change-functions
'org-indent-notify-modified-headline nil 'local) 'org-indent-notify-modified-headline nil 'local)
@ -213,7 +213,8 @@ during idle time."
(remove-hook 'filter-buffer-substring-functions (remove-hook 'filter-buffer-substring-functions
(lambda (fun start end delete) (lambda (fun start end delete)
(org-indent-remove-properties-from-string (org-indent-remove-properties-from-string
(funcall fun start end delete)))) (funcall fun start end delete)))
t)
(remove-hook 'after-change-functions 'org-indent-refresh-maybe 'local) (remove-hook 'after-change-functions 'org-indent-refresh-maybe 'local)
(remove-hook 'before-change-functions (remove-hook 'before-change-functions
'org-indent-notify-modified-headline 'local) 'org-indent-notify-modified-headline 'local)

View file

@ -3291,46 +3291,33 @@ These commands include \\[set-mark-command] and \\[start-kbd-macro]."
(defvar filter-buffer-substring-functions nil (defvar filter-buffer-substring-functions nil
"This variable is a wrapper hook around `filter-buffer-substring'. "This variable is a wrapper hook around `filter-buffer-substring'.")
Each member of the hook should be a function accepting four arguments: (make-obsolete-variable 'filter-buffer-substring-functions
\(FUN BEG END DELETE), where FUN is itself a function of three arguments 'filter-buffer-substring-function "24.4")
(defvar filter-buffer-substring-function #'buffer-substring--filter
"Function to perform the filtering in `filter-buffer-substring'.
The function is called with 3 arguments:
\(BEG END DELETE). The arguments BEG, END, and DELETE are the same \(BEG END DELETE). The arguments BEG, END, and DELETE are the same
as those of `filter-buffer-substring' in each case. as those of `filter-buffer-substring' in each case.
It should return the buffer substring between BEG and END, after filtering.")
The first hook function to be called receives a FUN equivalent
to the default operation of `filter-buffer-substring',
i.e. one that returns the buffer-substring between BEG and
END (processed by any `buffer-substring-filters'). Normally,
the hook function will call FUN and then do its own processing
of the result. The next hook function receives a FUN equivalent
to the previous hook function, calls it, and does its own
processing, and so on. The overall result is that of all hook
functions acting in sequence.
Any hook may choose not to call FUN though, in which case it
effectively replaces the default behavior with whatever it chooses.
Of course, a later hook function may do the same thing.")
(defvar buffer-substring-filters nil (defvar buffer-substring-filters nil
"List of filter functions for `filter-buffer-substring'. "List of filter functions for `filter-buffer-substring'.
Each function must accept a single argument, a string, and return Each function must accept a single argument, a string, and return
a string. The buffer substring is passed to the first function a string. The buffer substring is passed to the first function
in the list, and the return value of each function is passed to in the list, and the return value of each function is passed to
the next. The final result (if `buffer-substring-filters' is the next.
nil, this is the unfiltered buffer-substring) is passed to the
first function on `filter-buffer-substring-functions'.
As a special convention, point is set to the start of the buffer text As a special convention, point is set to the start of the buffer text
being operated on (i.e., the first argument of `filter-buffer-substring') being operated on (i.e., the first argument of `filter-buffer-substring')
before these functions are called.") before these functions are called.")
(make-obsolete-variable 'buffer-substring-filters (make-obsolete-variable 'buffer-substring-filters
'filter-buffer-substring-functions "24.1") 'filter-buffer-substring-function "24.1")
(defun filter-buffer-substring (beg end &optional delete) (defun filter-buffer-substring (beg end &optional delete)
"Return the buffer substring between BEG and END, after filtering. "Return the buffer substring between BEG and END, after filtering.
The wrapper hook `filter-buffer-substring-functions' performs The hook `filter-buffer-substring-function' performs the actual filtering.
the actual filtering. The obsolete variable `buffer-substring-filters' By default, no filtering is done.
is also consulted. If both of these are nil, no filtering is done.
If DELETE is non-nil, the text between BEG and END is deleted If DELETE is non-nil, the text between BEG and END is deleted
from the buffer. from the buffer.
@ -3338,9 +3325,12 @@ from the buffer.
This function should be used instead of `buffer-substring', This function should be used instead of `buffer-substring',
`buffer-substring-no-properties', or `delete-and-extract-region' `buffer-substring-no-properties', or `delete-and-extract-region'
when you want to allow filtering to take place. For example, when you want to allow filtering to take place. For example,
major or minor modes can use `filter-buffer-substring-functions' to major or minor modes can use `filter-buffer-substring-function' to
extract characters that are special to a buffer, and should not extract characters that are special to a buffer, and should not
be copied into other buffers." be copied into other buffers."
(funcall filter-buffer-substring-function beg end delete))
(defun buffer-substring--filter (beg end &optional delete)
(with-wrapper-hook filter-buffer-substring-functions (beg end delete) (with-wrapper-hook filter-buffer-substring-functions (beg end delete)
(cond (cond
((or delete buffer-substring-filters) ((or delete buffer-substring-filters)

View file

@ -1414,7 +1414,9 @@ Of course, a subsequent hook function may do the same thing.
Each hook function definition is used to construct the FUN passed Each hook function definition is used to construct the FUN passed
to the next hook function, if any. The last (or \"outermost\") to the next hook function, if any. The last (or \"outermost\")
FUN is then called once." FUN is then called once."
(declare (indent 2) (debug (form sexp body))) (declare (indent 2) (debug (form sexp body))
(obsolete "use a <foo>-function variable modified by add-function."
"24.4"))
;; We need those two gensyms because CL's lexical scoping is not available ;; We need those two gensyms because CL's lexical scoping is not available
;; for function arguments :-( ;; for function arguments :-(
(let ((funs (make-symbol "funs")) (let ((funs (make-symbol "funs"))