comparison lisp/simple.el @ 106109:42ca82b4620b

* abbrev.el (abbrev-with-wrapper-hook): (re)move... * simple.el (with-wrapper-hook): ...to here. Add argument `args'. * minibuffer.el (completion-in-region-functions): New hook. (completion-in-region): New function. * emacs-lisp/lisp.el (lisp-complete-symbol): * pcomplete.el (pcomplete-std-complete): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 19 Nov 2009 03:12:51 +0000
parents 11d369ec41c4
children 62c0a89cd695
comparison
equal deleted inserted replaced
106108:48d6337584da 106109:42ca82b4620b
6477 (set (make-local-variable 'vis-mode-saved-buffer-invisibility-spec) 6477 (set (make-local-variable 'vis-mode-saved-buffer-invisibility-spec)
6478 buffer-invisibility-spec) 6478 buffer-invisibility-spec)
6479 (setq buffer-invisibility-spec nil))) 6479 (setq buffer-invisibility-spec nil)))
6480 6480
6481 ;; Partial application of functions (similar to "currying"). 6481 ;; Partial application of functions (similar to "currying").
6482 ;; This function is here rather than in subr.el because it uses CL.
6482 (defun apply-partially (fun &rest args) 6483 (defun apply-partially (fun &rest args)
6483 "Return a function that is a partial application of FUN to ARGS. 6484 "Return a function that is a partial application of FUN to ARGS.
6484 ARGS is a list of the first N arguments to pass to FUN. 6485 ARGS is a list of the first N arguments to pass to FUN.
6485 The result is a new function which does the same as FUN, except that 6486 The result is a new function which does the same as FUN, except that
6486 the first N arguments are fixed at the values with which this function 6487 the first N arguments are fixed at the values with which this function
6487 was called." 6488 was called."
6488 (lexical-let ((fun fun) (args1 args)) 6489 (lexical-let ((fun fun) (args1 args))
6489 (lambda (&rest args2) (apply fun (append args1 args2))))) 6490 (lambda (&rest args2) (apply fun (append args1 args2)))))
6491
6492 ;; This function is here rather than in subr.el because it uses CL.
6493 (defmacro with-wrapper-hook (var args &rest body)
6494 "Run BODY wrapped with the VAR hook.
6495 VAR is a special hook: its functions are called with a first argument
6496 which is the \"original\" code (the BODY), so the hook function can wrap
6497 the original function, or call it any number of times (including not calling
6498 it at all). This is similar to an `around' advice.
6499 VAR is normally a symbol (a variable) in which case it is treated like
6500 a hook, with a buffer-local and a global part. But it can also be an
6501 arbitrary expression.
6502 ARGS is a list of variables which will be passed as additional arguments
6503 to each function, after the inital argument, and which the first argument
6504 expects to receive when called."
6505 (declare (indent 2) (debug t))
6506 ;; We need those two gensyms because CL's lexical scoping is not available
6507 ;; for function arguments :-(
6508 (let ((funs (make-symbol "funs"))
6509 (global (make-symbol "global"))
6510 (argssym (make-symbol "args")))
6511 ;; Since the hook is a wrapper, the loop has to be done via
6512 ;; recursion: a given hook function will call its parameter in order to
6513 ;; continue looping.
6514 `(labels ((runrestofhook (,funs ,global ,argssym)
6515 ;; `funs' holds the functions left on the hook and `global'
6516 ;; holds the functions left on the global part of the hook
6517 ;; (in case the hook is local).
6518 (lexical-let ((funs ,funs)
6519 (global ,global))
6520 (if (consp funs)
6521 (if (eq t (car funs))
6522 (apply 'runrestofhook
6523 (append global (cdr funs)) nil ,argssym)
6524 (apply (car funs)
6525 (lambda (&rest args)
6526 (runrestofhook (cdr funs) global args))
6527 ,argssym))
6528 ;; Once there are no more functions on the hook, run
6529 ;; the original body.
6530 (apply (lambda ,args ,@body) ,argssym)))))
6531 (runrestofhook ,var
6532 ;; The global part of the hook, if any.
6533 ,(if (symbolp var)
6534 `(if (local-variable-p ',var)
6535 (default-value ',var)))
6536 (list ,@args)))))
6490 6537
6491 ;; Minibuffer prompt stuff. 6538 ;; Minibuffer prompt stuff.
6492 6539
6493 ;(defun minibuffer-prompt-modification (start end) 6540 ;(defun minibuffer-prompt-modification (start end)
6494 ; (error "You cannot modify the prompt")) 6541 ; (error "You cannot modify the prompt"))