aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2013-10-07 09:28:34 +0800
committerLeo Liu2013-10-07 09:28:34 +0800
commit85698d63495d7bb22997eedbb74cef7f20d18ffd (patch)
tree9ec4dcd2587dd935e1b22de9353fb555df43df28
parent568e370dad062763135518ee453ebd6f9186a581 (diff)
downloademacs-85698d63495d7bb22997eedbb74cef7f20d18ffd.tar.gz
emacs-85698d63495d7bb22997eedbb74cef7f20d18ffd.zip
* register.el (register-preview-delay)
(register-preview-functions): New variables. (register-read-with-preview, register-preview) (register-describe-oneline): New functions. (point-to-register, window-configuration-to-register) (frame-configuration-to-register, jump-to-register) (number-to-register, view-register, insert-register) (copy-to-register, append-to-register, prepend-to-register) (copy-rectangle-to-register): Use register-read-with-preview to read register. Fixes: debbugs:15525
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/register.el113
2 files changed, 113 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 94b10ac97f5..9211dfe2356 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12013-10-07 Leo Liu <sdl.web@gmail.com>
2
3 * register.el (register-preview-delay)
4 (register-preview-functions): New variables.
5 (register-read-with-preview, register-preview)
6 (register-describe-oneline): New functions.
7 (point-to-register, window-configuration-to-register)
8 (frame-configuration-to-register, jump-to-register)
9 (number-to-register, view-register, insert-register)
10 (copy-to-register, append-to-register, prepend-to-register)
11 (copy-rectangle-to-register): Use register-read-with-preview to
12 read register. (Bug#15525)
13
12013-10-06 Dato Simó <dato@net.com.org.es> (tiny change) 142013-10-06 Dato Simó <dato@net.com.org.es> (tiny change)
2 15
3 * net/network-stream.el (network-stream-open-starttls): Don't add 16 * net/network-stream.el (network-stream-open-starttls): Don't add
diff --git a/lisp/register.el b/lisp/register.el
index 78f18dbc7c1..a44218fa135 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -1,4 +1,4 @@
1;;; register.el --- register commands for Emacs 1;;; register.el --- register commands for Emacs -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 1985, 1993-1994, 2001-2013 Free Software Foundation, 3;; Copyright (C) 1985, 1993-1994, 2001-2013 Free Software Foundation,
4;; Inc. 4;; Inc.
@@ -89,6 +89,11 @@ text."
89 :type '(choice (const :tag "None" nil) 89 :type '(choice (const :tag "None" nil)
90 (character :tag "Use register" :value ?+))) 90 (character :tag "Use register" :value ?+)))
91 91
92(defcustom register-preview-delay 1
93 "If non-nil delay in seconds to pop up the preview window."
94 :type '(choice number (const :tag "Indefinitely" nil))
95 :group 'register)
96
92(defun get-register (register) 97(defun get-register (register)
93 "Return contents of Emacs register named REGISTER, or nil if none." 98 "Return contents of Emacs register named REGISTER, or nil if none."
94 (cdr (assq register register-alist))) 99 (cdr (assq register register-alist)))
@@ -102,12 +107,73 @@ See the documentation of the variable `register-alist' for possible VALUEs."
102 (push (cons register value) register-alist)) 107 (push (cons register value) register-alist))
103 value)) 108 value))
104 109
110(defun register-describe-oneline (c)
111 "One-line description of register C."
112 (let ((d (replace-regexp-in-string
113 "\n[ \t]*" " "
114 (with-output-to-string (describe-register-1 c)))))
115 (if (string-match "Register.+? contains \\(?:an? \\|the \\)?" d)
116 (substring d (match-end 0))
117 d)))
118
119(defvar register-preview-functions nil)
120
121(defun register-preview (buffer &optional show-empty)
122 "Pop up a window to show register preview in BUFFER.
123If SHOW-EMPTY is non-nil show the window even if no registers."
124 (when (or show-empty (consp register-alist))
125 (let ((split-height-threshold 0))
126 ;; XXX: why with-temp-buffer-window always pops up the temp
127 ;; window even if one already shown?
128 (with-temp-buffer-window
129 buffer
130 (cons 'display-buffer-below-selected
131 '((window-height . fit-window-to-buffer)))
132 nil
133 (with-current-buffer standard-output
134 (setq cursor-in-non-selected-windows nil)
135 (mapc
136 (lambda (r)
137 (insert (or (run-hook-with-args-until-success
138 'register-preview-functions r)
139 (format "%s %s\n"
140 (concat (single-key-description (car r)) ":")
141 (register-describe-oneline (car r))))))
142 register-alist))))))
143
144(defun register-read-with-preview (prompt)
145 "Read an event with register preview using PROMPT.
146Pop up a register preview window if the input is a help char but
147is not a register. Alternatively if `register-preview-delay' is a
148number the preview window is popped up after some delay."
149 (let* ((buffer "*Register Preview*")
150 (timer (when (numberp register-preview-delay)
151 (run-with-timer register-preview-delay nil
152 (lambda ()
153 (unless (get-buffer-window buffer)
154 (register-preview buffer))))))
155 (help-chars (cl-loop for c in (cons help-char help-event-list)
156 when (not (get-register c))
157 collect c)))
158 (unwind-protect
159 (progn
160 (while (memq (read-event (propertize prompt 'face 'minibuffer-prompt))
161 help-chars)
162 (unless (get-buffer-window buffer)
163 (register-preview buffer 'show-empty)))
164 last-input-event)
165 (and (timerp timer) (cancel-timer timer))
166 (let ((w (get-buffer-window buffer)))
167 (and (window-live-p w) (delete-window w)))
168 (and (get-buffer buffer) (kill-buffer buffer)))))
169
105(defun point-to-register (register &optional arg) 170(defun point-to-register (register &optional arg)
106 "Store current location of point in register REGISTER. 171 "Store current location of point in register REGISTER.
107With prefix argument, store current frame configuration. 172With prefix argument, store current frame configuration.
108Use \\[jump-to-register] to go to that location or restore that configuration. 173Use \\[jump-to-register] to go to that location or restore that configuration.
109Argument is a character, naming the register." 174Argument is a character, naming the register."
110 (interactive "cPoint to register: \nP") 175 (interactive (list (register-read-with-preview "Point to register: ")
176 current-prefix-arg))
111 ;; Turn the marker into a file-ref if the buffer is killed. 177 ;; Turn the marker into a file-ref if the buffer is killed.
112 (add-hook 'kill-buffer-hook 'register-swap-out nil t) 178 (add-hook 'kill-buffer-hook 'register-swap-out nil t)
113 (set-register register 179 (set-register register
@@ -118,7 +184,9 @@ Argument is a character, naming the register."
118 "Store the window configuration of the selected frame in register REGISTER. 184 "Store the window configuration of the selected frame in register REGISTER.
119Use \\[jump-to-register] to restore the configuration. 185Use \\[jump-to-register] to restore the configuration.
120Argument is a character, naming the register." 186Argument is a character, naming the register."
121 (interactive "cWindow configuration to register: \nP") 187 (interactive (list (register-read-with-preview
188 "Window configuration to register: ")
189 current-prefix-arg))
122 ;; current-window-configuration does not include the value 190 ;; current-window-configuration does not include the value
123 ;; of point in the current buffer, so record that separately. 191 ;; of point in the current buffer, so record that separately.
124 (set-register register (list (current-window-configuration) (point-marker)))) 192 (set-register register (list (current-window-configuration) (point-marker))))
@@ -127,7 +195,9 @@ Argument is a character, naming the register."
127 "Store the window configuration of all frames in register REGISTER. 195 "Store the window configuration of all frames in register REGISTER.
128Use \\[jump-to-register] to restore the configuration. 196Use \\[jump-to-register] to restore the configuration.
129Argument is a character, naming the register." 197Argument is a character, naming the register."
130 (interactive "cFrame configuration to register: \nP") 198 (interactive (list (register-read-with-preview
199 "Frame configuration to register: ")
200 current-prefix-arg))
131 ;; current-frame-configuration does not include the value 201 ;; current-frame-configuration does not include the value
132 ;; of point in the current buffer, so record that separately. 202 ;; of point in the current buffer, so record that separately.
133 (set-register register (list (current-frame-configuration) (point-marker)))) 203 (set-register register (list (current-frame-configuration) (point-marker))))
@@ -143,7 +213,8 @@ First argument is a character, naming the register.
143Optional second arg non-nil (interactively, prefix argument) says to 213Optional second arg non-nil (interactively, prefix argument) says to
144delete any existing frames that the frameset doesn't mention. 214delete any existing frames that the frameset doesn't mention.
145\(Otherwise, these frames are iconified.)" 215\(Otherwise, these frames are iconified.)"
146 (interactive "cJump to register: \nP") 216 (interactive (list (register-read-with-preview "Jump to register: ")
217 current-prefix-arg))
147 (let ((val (get-register register))) 218 (let ((val (get-register register)))
148 (cond 219 (cond
149 ((registerv-p val) 220 ((registerv-p val)
@@ -190,7 +261,8 @@ Two args, NUMBER and REGISTER (a character, naming the register).
190If NUMBER is nil, a decimal number is read from the buffer starting 261If NUMBER is nil, a decimal number is read from the buffer starting
191at point, and point moves to the end of that number. 262at point, and point moves to the end of that number.
192Interactively, NUMBER is the prefix arg (none means nil)." 263Interactively, NUMBER is the prefix arg (none means nil)."
193 (interactive "P\ncNumber to register: ") 264 (interactive (list current-prefix-arg
265 (register-read-with-preview "Number to register: ")))
194 (set-register register 266 (set-register register
195 (if number 267 (if number
196 (prefix-numeric-value number) 268 (prefix-numeric-value number)
@@ -222,7 +294,7 @@ If REGISTER is empty or if it contains text, call
222(defun view-register (register) 294(defun view-register (register)
223 "Display what is contained in register named REGISTER. 295 "Display what is contained in register named REGISTER.
224The Lisp value REGISTER is a character." 296The Lisp value REGISTER is a character."
225 (interactive "cView register: ") 297 (interactive (list (register-read-with-preview "View register: ")))
226 (let ((val (get-register register))) 298 (let ((val (get-register register)))
227 (if (null val) 299 (if (null val)
228 (message "Register %s is empty" (single-key-description register)) 300 (message "Register %s is empty" (single-key-description register))
@@ -323,7 +395,10 @@ The Lisp value REGISTER is a character."
323Normally puts point before and mark after the inserted text. 395Normally puts point before and mark after the inserted text.
324If optional second arg is non-nil, puts mark before and point after. 396If optional second arg is non-nil, puts mark before and point after.
325Interactively, second arg is non-nil if prefix arg is supplied." 397Interactively, second arg is non-nil if prefix arg is supplied."
326 (interactive "*cInsert register: \nP") 398 (interactive (progn
399 (barf-if-buffer-read-only)
400 (register-read-with-preview "Insert register: ")
401 current-prefix-arg))
327 (push-mark) 402 (push-mark)
328 (let ((val (get-register register))) 403 (let ((val (get-register register)))
329 (cond 404 (cond
@@ -349,7 +424,10 @@ Interactively, second arg is non-nil if prefix arg is supplied."
349With prefix arg, delete as well. 424With prefix arg, delete as well.
350Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. 425Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
351START and END are buffer positions indicating what to copy." 426START and END are buffer positions indicating what to copy."
352 (interactive "cCopy to register: \nr\nP") 427 (interactive (list (register-read-with-preview "Copy to register: ")
428 (region-beginning)
429 (region-end)
430 current-prefix-arg))
353 (set-register register (filter-buffer-substring start end)) 431 (set-register register (filter-buffer-substring start end))
354 (setq deactivate-mark t) 432 (setq deactivate-mark t)
355 (cond (delete-flag 433 (cond (delete-flag
@@ -362,7 +440,10 @@ START and END are buffer positions indicating what to copy."
362With prefix arg, delete as well. 440With prefix arg, delete as well.
363Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. 441Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
364START and END are buffer positions indicating what to append." 442START and END are buffer positions indicating what to append."
365 (interactive "cAppend to register: \nr\nP") 443 (interactive (list (register-read-with-preview "Append to register: ")
444 (region-beginning)
445 (region-end)
446 current-prefix-arg))
366 (let ((reg (get-register register)) 447 (let ((reg (get-register register))
367 (text (filter-buffer-substring start end)) 448 (text (filter-buffer-substring start end))
368 (separator (and register-separator (get-register register-separator)))) 449 (separator (and register-separator (get-register register-separator))))
@@ -381,7 +462,10 @@ START and END are buffer positions indicating what to append."
381With prefix arg, delete as well. 462With prefix arg, delete as well.
382Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. 463Called from program, takes four args: REGISTER, START, END and DELETE-FLAG.
383START and END are buffer positions indicating what to prepend." 464START and END are buffer positions indicating what to prepend."
384 (interactive "cPrepend to register: \nr\nP") 465 (interactive (list (register-read-with-preview "Prepend to register: ")
466 (region-beginning)
467 (region-end)
468 current-prefix-arg))
385 (let ((reg (get-register register)) 469 (let ((reg (get-register register))
386 (text (filter-buffer-substring start end)) 470 (text (filter-buffer-substring start end))
387 (separator (and register-separator (get-register register-separator)))) 471 (separator (and register-separator (get-register register-separator))))
@@ -402,7 +486,11 @@ To insert this register in the buffer, use \\[insert-register].
402 486
403Called from a program, takes four args: REGISTER, START, END and DELETE-FLAG. 487Called from a program, takes four args: REGISTER, START, END and DELETE-FLAG.
404START and END are buffer positions giving two corners of rectangle." 488START and END are buffer positions giving two corners of rectangle."
405 (interactive "cCopy rectangle to register: \nr\nP") 489 (interactive (list (register-read-with-preview
490 "Copy rectangle to register: ")
491 (region-beginning)
492 (region-end)
493 current-prefix-arg))
406 (let ((rectangle (if delete-flag 494 (let ((rectangle (if delete-flag
407 (delete-extract-rectangle start end) 495 (delete-extract-rectangle start end)
408 (extract-rectangle start end)))) 496 (extract-rectangle start end))))
@@ -412,6 +500,5 @@ START and END are buffer positions giving two corners of rectangle."
412 (setq deactivate-mark t) 500 (setq deactivate-mark t)
413 (indicate-copied-region (length (car rectangle)))))) 501 (indicate-copied-region (length (car rectangle))))))
414 502
415
416(provide 'register) 503(provide 'register)
417;;; register.el ends here 504;;; register.el ends here