| 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 |
(require 'erc) |
|---|
| 40 |
(require 'comint) |
|---|
| 41 |
(require 'ring) |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
(define-erc-module ring nil |
|---|
| 45 |
"Stores input in a ring so that previous commands and messages can |
|---|
| 46 |
be recalled using M-p and M-n." |
|---|
| 47 |
((add-hook 'erc-send-pre-hook 'erc-add-to-input-ring) |
|---|
| 48 |
(define-key erc-mode-map "\M-p" 'erc-previous-command) |
|---|
| 49 |
(define-key erc-mode-map "\M-n" 'erc-next-command)) |
|---|
| 50 |
((remove-hook 'erc-send-pre-hook 'erc-add-to-input-ring) |
|---|
| 51 |
(define-key erc-mode-map "\M-p" 'undefined) |
|---|
| 52 |
(define-key erc-mode-map "\M-n" 'undefined))) |
|---|
| 53 |
|
|---|
| 54 |
(defvar erc-input-ring nil "Input ring for erc.") |
|---|
| 55 |
(make-variable-buffer-local 'erc-input-ring) |
|---|
| 56 |
|
|---|
| 57 |
(defvar erc-input-ring-index nil |
|---|
| 58 |
"Position in the input ring for erc. |
|---|
| 59 |
If nil, the input line is blank and the user is conceptually 'after' |
|---|
| 60 |
the most recently added item in the ring. If an integer, the input |
|---|
| 61 |
line is non-blank and displays the item from the ring indexed by this |
|---|
| 62 |
variable.") |
|---|
| 63 |
(make-variable-buffer-local 'erc-input-ring-index) |
|---|
| 64 |
|
|---|
| 65 |
(defun erc-input-ring-setup () |
|---|
| 66 |
"Do the setup required so that we can use comint style input rings. |
|---|
| 67 |
Call this function when setting up the mode." |
|---|
| 68 |
(setq erc-input-ring (make-ring comint-input-ring-size)) |
|---|
| 69 |
(setq erc-input-ring-index nil)) |
|---|
| 70 |
|
|---|
| 71 |
(defun erc-add-to-input-ring (s) |
|---|
| 72 |
"Add string S to the input ring and reset history position." |
|---|
| 73 |
(unless erc-input-ring (erc-input-ring-setup)) |
|---|
| 74 |
(ring-insert erc-input-ring s) |
|---|
| 75 |
(setq erc-input-ring-index nil)) |
|---|
| 76 |
|
|---|
| 77 |
(defun erc-clear-input-ring () |
|---|
| 78 |
"Remove all entries from the input ring, then call garbage-collect. |
|---|
| 79 |
You might use this for security purposes if you have typed a command |
|---|
| 80 |
containing a password." |
|---|
| 81 |
(interactive) |
|---|
| 82 |
(setq erc-input-ring (make-ring comint-input-ring-size) |
|---|
| 83 |
erc-input-ring-index nil) |
|---|
| 84 |
(garbage-collect) |
|---|
| 85 |
(message "ERC input ring cleared.")) |
|---|
| 86 |
|
|---|
| 87 |
(defun erc-previous-command () |
|---|
| 88 |
"Replace current command with the previous one from the history." |
|---|
| 89 |
(interactive) |
|---|
| 90 |
(unless erc-input-ring (erc-input-ring-setup)) |
|---|
| 91 |
|
|---|
| 92 |
(when (> (ring-length erc-input-ring) 0) |
|---|
| 93 |
(if (and erc-input-ring-index |
|---|
| 94 |
(= (ring-length erc-input-ring) (1+ erc-input-ring-index))) |
|---|
| 95 |
(progn |
|---|
| 96 |
(erc-replace-current-command "") |
|---|
| 97 |
(setq erc-input-ring-index nil)) |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
(if (null erc-input-ring-index) |
|---|
| 104 |
(when (> (point-max) erc-input-marker) |
|---|
| 105 |
(erc-add-to-input-ring (buffer-substring erc-input-marker |
|---|
| 106 |
(point-max))) |
|---|
| 107 |
(setq erc-input-ring-index 0))) |
|---|
| 108 |
|
|---|
| 109 |
(setq erc-input-ring-index (if erc-input-ring-index |
|---|
| 110 |
(ring-plus1 erc-input-ring-index |
|---|
| 111 |
(ring-length erc-input-ring)) |
|---|
| 112 |
0)) |
|---|
| 113 |
(erc-replace-current-command (ring-ref erc-input-ring |
|---|
| 114 |
erc-input-ring-index))))) |
|---|
| 115 |
|
|---|
| 116 |
(defun erc-next-command () |
|---|
| 117 |
"Replace current command with the next one from the history." |
|---|
| 118 |
(interactive) |
|---|
| 119 |
(unless erc-input-ring (erc-input-ring-setup)) |
|---|
| 120 |
|
|---|
| 121 |
(when (> (ring-length erc-input-ring) 0) |
|---|
| 122 |
(if (and erc-input-ring-index |
|---|
| 123 |
(= 0 erc-input-ring-index)) |
|---|
| 124 |
(progn |
|---|
| 125 |
(erc-replace-current-command "") |
|---|
| 126 |
(setq erc-input-ring-index nil)) |
|---|
| 127 |
(setq erc-input-ring-index (ring-minus1 (or erc-input-ring-index 0) |
|---|
| 128 |
(ring-length erc-input-ring))) |
|---|
| 129 |
(erc-replace-current-command (ring-ref erc-input-ring |
|---|
| 130 |
erc-input-ring-index))))) |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
(defun erc-replace-current-command (s) |
|---|
| 134 |
"Replace current command with string S." |
|---|
| 135 |
|
|---|
| 136 |
(let ((inhibit-read-only t)) |
|---|
| 137 |
(delete-region |
|---|
| 138 |
(progn (goto-char erc-insert-marker) (erc-bol)) |
|---|
| 139 |
(goto-char (point-max))) |
|---|
| 140 |
(insert s))) |
|---|
| 141 |
|
|---|
| 142 |
(provide 'erc-ring) |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|