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
This commit is contained in:
Glenn Morris 2014-02-01 17:04:08 -08:00
parent 28e6cee817
commit 7c3247627a
5 changed files with 39 additions and 12 deletions

View file

@ -1,3 +1,7 @@
2014-02-02 Glenn Morris <rgm@gnu.org>
* regs.texi (Registers): Mention previewing.
2014-01-29 Glenn Morris <rgm@gnu.org>
* killing.texi (Deletion): Mention cycle-spacing.

View file

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

View file

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

View file

@ -1,3 +1,12 @@
2014-02-02 Glenn Morris <rgm@gnu.org>
* 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 <dgutov@yandex.ru>
* progmodes/ruby-mode.el (ruby-smie--implicit-semi-p): Check for

View file

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