/
BetterRegisters
80 lines (60 loc) · 3.82 KB
/
BetterRegisters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
== The better-registers.el package ==
There can only be one thing in a [[register]] at a single point of time, so why have different keybindings for using whats in a register?
With Lisp:better-registers.el, a small package by SigurdMeldgaard you can use whatever is in a register by pressing `C-j'.
That is one of
* Jump to another [[buffer]], position or file (stored with `C-r b', `C-r SPC', or `C-r p' respectively)
* Restore a [[window]] or [[frame]] configuration (saved with `C-r w' or `C-r f')
* Insert a saved string or [[rectangle]] (saved with: `C-r s' or `C-r r')
* Insert a number (saved with: `C-u' number `C-r n')
* Play back a [[keyboard macro]] (first record it with ##`<S-f1>'##...do stuff..., ##`<S-f1>'##. Then store it in register with `C-r m')
With this package you can also save all the registers (except for those containing frame or window-configurations) in a file for using them at later sessions.
== Other nifty tricks for better use of registers ==
Remember you have registers for both capital and non-capital letters.
Numbers in registers together with the command increment-register are nice for use in semi-advanced keyboard-macros.
= Nice register-related stuff for your .emacs =
Here are some simple improvements you can make:
;; Just do this if you want registers to be buffer local.
(make-variable-buffer-local 'register-alist) ; it's global by default
;; This is used in the function below to make marked points visible
(defface register-marker-face '((t (:background "grey")))
"Used to mark register positions in a buffer."
:group 'faces)
This redefines (and therefore overrides) the standard function of the same name. Highlights points that are 'registered' and floatover help tells what register key the point was mapped to.
(defun set-register (register value)
"Set Emacs register named REGISTER to VALUE. Returns VALUE.
See the documentation of `register-alist' for possible VALUE."
(let ((aelt (assq register register-alist))
(sovl (intern (concat "point-register-overlay-"
(single-key-description register))))
)
(when (not (boundp sovl))
(set sovl (make-overlay (point)(point)))
(overlay-put (symbol-value sovl) 'face 'register-marker-face)
(overlay-put (symbol-value sovl) 'help-echo
(concat "Register: `"
(single-key-description register) "'")))
(delete-overlay (symbol-value sovl))
(if (markerp value)
;; I'm trying to avoid putting overlay on newline char
(if (and (looking-at "$")(not (looking-back "^")))
(move-overlay (symbol-value sovl) (1- value) value)
(move-overlay (symbol-value sovl) value (1+ value))))
(if aelt
(setcdr aelt value)
(push (cons register value) register-alist))
value))
= Make registers act more like cut/copy/paste =
Add a little extra code to your .emacs to make F12/C-F12/C-S-F12 perform register-based paste/copy/cut functions, respectively:
(global-set-key (kbd "<f12>") (lambda (char)
(interactive "cInsert Register:")
(insert-register char 't)))
(global-set-key (kbd "<C-f12>") (lambda (char)
(interactive "cCopy to Register:")
(copy-to-register char (region-beginning) (region-end))
(cua-cancel)))
(global-set-key (kbd "<C-S-f12>") (lambda (char)
(interactive "cCut to Register:")
(copy-to-register char (region-beginning) (region-end))
(cua-delete-region)))
----
CategoryEditing