Commit d36ed1c8 authored by Stefan Monnier's avatar Stefan Monnier

* 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.
parent 04754d36
......@@ -329,6 +329,13 @@ file using `set-file-extended-attributes'.
*** `field-complete'
*** `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'.
** Support for filesystem notifications.
......
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>
* progmodes/python.el (python-nav--syntactically): Fix cornercases
......
......@@ -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."
:type 'hook
: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)
"Undefine all abbrevs in abbrev table TABLE, leaving it empty."
......@@ -832,10 +832,12 @@ see `define-abbrev' for details."
value))
(defvar abbrev-expand-functions nil
"Wrapper hook around `expand-abbrev'.
The functions on this special hook are called with one argument:
a function that performs the abbrev expansion. It should return
the abbrev symbol if expansion took place.")
"Wrapper hook around `expand-abbrev'.")
(make-obsolete-variable 'abbrev-expand-functions 'abbrev-expand-function "24.4")
(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 ()
"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'.)"
(interactive)
(run-hooks 'pre-abbrev-expand-hook)
(funcall abbrev-expand-function))
(defun abbrev--default-expand ()
(with-wrapper-hook abbrev-expand-functions ()
(pcase-let ((`(,sym ,name ,wordstart ,wordend) (abbrev--before-point)))
(when sym
......
......@@ -44,7 +44,9 @@
(: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)
(: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.
Each element has the form (WHERE BYTECODE STACK) where:
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
(defmacro add-function (where place function &optional props)
;; TODO:
;; - obsolete with-wrapper-hook (mostly requires buffer-local support).
;; - provide some kind of control over ordering. E.g. debug-on-entry, ELP
;; and tracing want to stay first.
;; - 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)))
`:after-while' (lambda (&rest r) (and (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.
PROPS is an alist of additional properties, among which the following have
a special meaning:
......
......@@ -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)))
(build-mail-abbrevs)))
(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))
(defun mail-abbrevs-enable ()
......
......@@ -1764,14 +1764,15 @@ variables.")
(exit-minibuffer))
(defvar completion-in-region-functions nil
"Wrapper hook around `completion-in-region'.
The functions on this special hook are called with 5 arguments:
NEXT-FUN START END COLLECTION PREDICATE.
NEXT-FUN is a function of four arguments (START END COLLECTION PREDICATE)
that performs the default operation. The other four arguments are like
the ones passed to `completion-in-region'. The functions on this hook
are expected to perform completion on START..END using COLLECTION
and PREDICATE, either by calling NEXT-FUN or by doing it themselves.")
"Wrapper hook around `completion-in-region'.")
(make-obsolete-variable 'completion-in-region-functions
'completion-in-region-function "24.4")
(defvar completion-in-region-function #'completion--in-region
"Function to perform the job of `completion-in-region'.
The function is called with 4 arguments: START END COLLECTION PREDICATE.
The arguments and expected return value are like the ones of
`completion-in-region'.")
(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
exit."
(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
;; FIXME: Maybe we should use this hook to provide a "display
;; completions" operation as well.
......
This diff is collapsed.
......@@ -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 'pre-command-hook 'org-unhighlight nil 'local)
;; Make sure properties are removed when copying text
(make-local-variable 'filter-buffer-substring-functions)
(add-hook 'filter-buffer-substring-functions
(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
(setq org-agenda-follow-mode org-agenda-start-with-follow-mode
org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
......
......@@ -182,11 +182,11 @@ during idle time."
(org-set-local 'org-hide-leading-stars-before-indent-mode
org-hide-leading-stars)
(org-set-local 'org-hide-leading-stars t))
(make-local-variable 'filter-buffer-substring-functions)
(add-hook 'filter-buffer-substring-functions
(lambda (fun start end delete)
(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 'before-change-functions
'org-indent-notify-modified-headline nil 'local)
......@@ -213,7 +213,8 @@ during idle time."
(remove-hook 'filter-buffer-substring-functions
(lambda (fun start end delete)
(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 'before-change-functions
'org-indent-notify-modified-headline 'local)
......
......@@ -3291,46 +3291,33 @@ These commands include \\[set-mark-command] and \\[start-kbd-macro]."
(defvar filter-buffer-substring-functions nil
"This variable is a wrapper hook around `filter-buffer-substring'.
Each member of the hook should be a function accepting four arguments:
\(FUN BEG END DELETE), where FUN is itself a function of three arguments
"This variable is a wrapper hook around `filter-buffer-substring'.")
(make-obsolete-variable 'filter-buffer-substring-functions
'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
as those of `filter-buffer-substring' in each case.
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.")
It should return the buffer substring between BEG and END, after filtering.")
(defvar buffer-substring-filters nil
"List of filter functions for `filter-buffer-substring'.
Each function must accept a single argument, a string, and return
a string. The buffer substring is passed to the first function
in the list, and the return value of each function is passed to
the next. The final result (if `buffer-substring-filters' is
nil, this is the unfiltered buffer-substring) is passed to the
first function on `filter-buffer-substring-functions'.
the next.
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')
before these functions are called.")
(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)
"Return the buffer substring between BEG and END, after filtering.
The wrapper hook `filter-buffer-substring-functions' performs
the actual filtering. The obsolete variable `buffer-substring-filters'
is also consulted. If both of these are nil, no filtering is done.
The hook `filter-buffer-substring-function' performs the actual filtering.
By default, no filtering is done.
If DELETE is non-nil, the text between BEG and END is deleted
from the buffer.
......@@ -3338,9 +3325,12 @@ from the buffer.
This function should be used instead of `buffer-substring',
`buffer-substring-no-properties', or `delete-and-extract-region'
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
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)
(cond
((or delete buffer-substring-filters)
......
......@@ -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
to the next hook function, if any. The last (or \"outermost\")
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
;; for function arguments :-(
(let ((funs (make-symbol "funs"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment