d)))
(defun register-preview-default (r)
- "Function that is the default value of the variable `register-preview-function'."
+ "Return a string describing the register R.
+
+This function is the default value of
+`register-preview-function', which see."
(format "%s: %s\n"
(single-key-description (car r))
(register-describe-oneline (car r))))
Called with one argument, a cons (NAME . CONTENTS) as found in `register-alist'.
The function should return a string, the description of the argument.")
-(defun register-preview (buffer &optional show-empty highlight)
+(defun register-preview (buffer &optional show-empty highlight pred)
"Pop up a window showing the registers preview in BUFFER.
If SHOW-EMPTY is non-nil, show the window even if no registers.
-Optional argument HIGHLIGHT says to highlight the description of
-a register with that name. Format of each entry is controlled by
-the variable `register-preview-function'."
+Third optional argument HIGHLIGHT says to highlight the
+description of a register with that name.
+
+Fourth optional argument PRED, if non-nil, is a function that
+takes the contents of a register and returns non-nil if the
+corresponding register should appear in the preview (see
+`register-preview' for the format of the register contents).
+
+The the variable `register-preview-function' controls the
+format of each entry in the preview."
(when (or show-empty (consp register-alist))
(with-current-buffer-window
- buffer
- (cons 'display-buffer-below-selected
- '((window-height . fit-window-to-buffer)
- (preserve-size . (nil . t))))
- nil
- (with-current-buffer standard-output
- (delete-region (point-min) (point-max))
- (setq cursor-in-non-selected-windows nil)
- (mapc (lambda (elem)
- (when-let ((name (car elem))
- (reg (get-register name))
- (desc (funcall register-preview-function elem)))
- (when (equal highlight name)
- (add-face-text-property 0 (length desc) 'match nil desc))
- (insert desc)))
- register-alist)))))
-
-(defun register-read-with-preview (prompt &optional confirm)
+ buffer
+ (cons 'display-buffer-below-selected
+ '((window-height . fit-window-to-buffer)
+ (preserve-size . (nil . t))))
+ nil
+ (with-current-buffer standard-output
+ (delete-region (point-min) (point-max))
+ (setq cursor-in-non-selected-windows nil)
+ (mapc (lambda (elem)
+ (let ((hilit nil)
+ (name (car elem))
+ (desc (funcall register-preview-function elem)))
+ (when (equal highlight name)
+ (add-face-text-property 0 (length desc) 'match nil desc)
+ (setq hilit t))
+ (when (or hilit
+ (null pred)
+ (funcall pred (cdr elem)))
+ (insert desc))))
+ register-alist)))))
+
+(defun register-read-with-preview (prompt &optional confirm pred)
"Read and return a register name, possibly showing existing registers.
-Prompt with the string PROMPT. Optional argument CONFIRM says to
-ask for confirmation if the register is already in use and
-`register-confirm-overwrite' is non-nil. If `register-alist' and
-`register-preview-delay' are both non-nil, display a window
+Prompt with the string PROMPT. Second optional argument CONFIRM
+says to ask for confirmation if the register is already in use
+and `register-confirm-overwrite' is non-nil. If `register-alist'
+and `register-preview-delay' are both non-nil, display a window
listing existing registers after `register-preview-delay'
-seconds. If `help-char' (or a member of `help-event-list') is
-pressed, display such a window regardless."
+seconds, or immediately in response to `help-char' (or a member
+of `help-event-list'). Third optional argument PRED is a
+predicate that registers must satisfy to appear in the preview,
+see `register-preview'."
(let* ((buffer "*Register Preview*")
(timer (when (numberp register-preview-delay)
(run-with-timer register-preview-delay nil
(lambda ()
(unless (get-buffer-window buffer)
- (register-preview buffer))))))
+ (register-preview buffer nil nil pred))))))
(help-chars (cl-loop for c in (cons help-char help-event-list)
when (not (get-register c))
collect c)))
(while (memq (read-key (propertize prompt 'face 'minibuffer-prompt))
help-chars)
(unless (get-buffer-window buffer)
- (register-preview buffer 'show-empty)))
+ (register-preview buffer 'show-empty nil pred)))
(cond
((or (eq ?\C-g last-input-event)
(eq 'escape last-input-event)
(keyboard-quit))
((and (get-register last-input-event)
confirm register-confirm-overwrite
- (not (progn
- (register-preview buffer nil last-input-event)
+ (not (let ((last-input-event last-input-event))
+ (register-preview buffer nil last-input-event pred)
(y-or-n-p (substitute-quotes
(format "Overwrite register `%s'?"
(single-key-description
(make-obsolete 'frame-configuration-to-register 'frameset-to-register "24.4")
+(declare-function frameset-register-p "frameset")
+
+(defun register-jump-p (contents)
+ "Return non-nil if \\[jump-to-register] can apply to register CONTENTS."
+ (or (and (registerv-p contents) (registerv-jump-func contents))
+ (markerp contents)
+ (and (consp contents)
+ (let ((cont (car contents)))
+ (or (frame-configuration-p cont)
+ (window-configuration-p cont)
+ (eq cont 'file)
+ (eq cont 'buffer)
+ (eq cont 'file-query))))
+ (and (featurep 'frameset) (frameset-register-p contents))))
+
(defalias 'register-to-point 'jump-to-register)
(defun jump-to-register (register &optional delete)
"Go to location stored in REGISTER, or restore configuration stored there.
ignored if the register contains anything but a frameset.
Interactively, prompt for REGISTER using `register-read-with-preview'."
- (interactive (list (register-read-with-preview "Jump to register: ")
+ (interactive (list (register-read-with-preview "Jump to register: "
+ nil #'register-jump-p)
current-prefix-arg))
(let ((val (get-register register)))
(register-val-jump-to val delete)))
(string-to-number (match-string 0)))
0))))
+(defun register-increment-p (contents)
+ "Return non-nil if \\[increment-register] can apply to register CONTENTS."
+ (or (numberp contents) (stringp contents)))
+
(defun increment-register (prefix register)
"Augment contents of REGISTER using PREFIX.
Interactively, PREFIX is the raw prefix argument.
Interactively, prompt for REGISTER using `register-read-with-preview'."
(interactive (list current-prefix-arg
- (register-read-with-preview "Increment register: ")))
+ (register-read-with-preview "Increment register: "
+ nil #'register-increment-p)))
(let ((register-val (get-register register)))
(cond
((numberp register-val)
(t
(princ "the empty string")))))
+(defun register-insert-p (contents)
+ "Return non-nil if \\[insert-register] can apply to register CONTENTS."
+ (or (and (registerv-p contents) (registerv-insert-func contents))
+ (stringp (car (ensure-list contents)))))
+
(defun insert-register (register &optional arg)
"Insert contents of REGISTER at point.
REGISTER is a character, the name of the register.
Interactively, prompt for REGISTER using `register-read-with-preview'."
(interactive (progn
(barf-if-buffer-read-only)
- (list (register-read-with-preview "Insert register: ")
+ (list (register-read-with-preview "Insert register: "
+ nil #'register-insert-p)
(not current-prefix-arg))))
(push-mark)
(let ((val (get-register register)))
Interactively, prompt for REGISTER using `register-read-with-preview',
and use mark and point as START and END."
- (interactive (list (register-read-with-preview "Append to register: ")
+ (interactive (list (register-read-with-preview "Append to register: "
+ nil #'stringp)
(region-beginning)
(region-end)
current-prefix-arg))
Interactively, prompt for REGISTER using `register-read-with-preview',
and use mark and point as START and END."
- (interactive (list (register-read-with-preview "Prepend to register: ")
+ (interactive (list (register-read-with-preview "Prepend to register: "
+ nil #'stringp)
(region-beginning)
(region-end)
current-prefix-arg))