From 7c3247627a102b53e9808ef51eca4a22c3a39fa3 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sat, 1 Feb 2014 17:04:08 -0800 Subject: [PATCH] register preview fixes * doc/emacs/regs.texi (Registers): Mention previewing. * lisp/register.el (register-preview-default): New function, split from register-preview. (register-preview-function): Rename from register-preview-functions, make it not a hook. (register-preview): Use register-preview-function. (register-read-with-preview): Error on non-character event. * etc/NEWS: Related markup. Fixes: debbugs:16595 --- doc/emacs/ChangeLog | 4 ++++ doc/emacs/regs.texi | 9 +++++++++ etc/NEWS | 3 ++- lisp/ChangeLog | 9 +++++++++ lisp/register.el | 26 +++++++++++++++----------- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 8f29d7c01f6..4478e4bd72c 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,3 +1,7 @@ +2014-02-02 Glenn Morris + + * regs.texi (Registers): Mention previewing. + 2014-01-29 Glenn Morris * killing.texi (Deletion): Mention cycle-spacing. diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi index 8ed0d848f59..8968cbbcffa 100644 --- a/doc/emacs/regs.texi +++ b/doc/emacs/regs.texi @@ -29,6 +29,15 @@ you store something else in that register. To see what register Display a description of what register @var{r} contains. @end table +@vindex register-preview-delay +@cindex preview of registers + All of the commands that prompt for a register will display a +``preview'' window that lists the existing registers (if there are +any) after a short delay. To change the length of the delay, +customize @code{register-preview-delay}. To prevent this display, set +that option to @code{nil}. You can explicitly request a preview +window by pressing @kbd{C-h} or @key{F1}. + @dfn{Bookmarks} record files and positions in them, so you can return to those positions when you look at the file again. Bookmarks are similar in spirit to registers, so they are also documented in diff --git a/etc/NEWS b/etc/NEWS index dcb8b13b1fd..0432c66612e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -301,6 +301,7 @@ bidirectional context. ** Register changes ++++ *** All interactive commands that read a register (`copy-to-register', etc.) now display a temporary window after `register-preview-delay' seconds that summarizes existing registers. To disable this, set that option to nil. @@ -930,7 +931,7 @@ It is layered as: function-carrying place, such as process-filters or `-function' hooks. *** advice-add/advice-remove to add/remove a piece of advice on a named -function,much like `defadvice' does. +function, much like `defadvice' does. ** New package frameset.el. It provides a set of operations to save a frameset (the state of all diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b2adc2cf881..11952ba98ee 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2014-02-02 Glenn Morris + + * register.el (register-preview-default): New function, + split from register-preview. + (register-preview-function): Rename from register-preview-functions, + make it not a hook. + (register-preview): Use register-preview-function. + (register-read-with-preview): Error on non-character event. (Bug#16595) + 2014-02-01 Dmitry Gutov * progmodes/ruby-mode.el (ruby-smie--implicit-semi-p): Check for diff --git a/lisp/register.el b/lisp/register.el index 798ea0615d1..cca09930611 100644 --- a/lisp/register.el +++ b/lisp/register.el @@ -119,11 +119,21 @@ See the documentation of the variable `register-alist' for possible VALUEs." (substring d (match-end 0)) d))) -(defvar register-preview-functions nil) +(defun register-preview-default (r) + "Default function for the variable `register-preview-function'." + (format "%s %s\n" + (concat (single-key-description (car r)) ":") + (register-describe-oneline (car r)))) + +(defvar register-preview-function #'register-preview-default + "Function to format a register for previewing. +Takes one argument, a cons (NAME . CONTENTS) as found in `register-alist'. +Returns a string.") (defun register-preview (buffer &optional show-empty) "Pop up a window to show register preview in BUFFER. -If SHOW-EMPTY is non-nil show the window even if no registers." +If SHOW-EMPTY is non-nil show the window even if no registers. +Format of each entry is controlled by the variable `register-preview-function'." (when (or show-empty (consp register-alist)) (with-temp-buffer-window buffer @@ -132,14 +142,7 @@ If SHOW-EMPTY is non-nil show the window even if no registers." nil (with-current-buffer standard-output (setq cursor-in-non-selected-windows nil) - (mapc - (lambda (r) - (insert (or (run-hook-with-args-until-success - 'register-preview-functions r) - (format "%s %s\n" - (concat (single-key-description (car r)) ":") - (register-describe-oneline (car r)))))) - register-alist))))) + (insert (mapconcat register-preview-function register-alist "")))))) (defun register-read-with-preview (prompt) "Read and return an event, prompting with PROMPT, possibly showing a preview. @@ -162,7 +165,8 @@ such a window regardless." help-chars) (unless (get-buffer-window buffer) (register-preview buffer 'show-empty))) - last-input-event) + (if (characterp last-input-event) last-input-event + (error "Non-character input-event"))) (and (timerp timer) (cancel-timer timer)) (let ((w (get-buffer-window buffer))) (and (window-live-p w) (delete-window w))) -- 2.39.2