Mercurial > hg > xemacs-beta
annotate lisp/register.el @ 5194:77907bd57d25
Add missing CL style fontification.
lisp/ChangeLog addition:
2010-04-07 Didier Verna <didier@xemacs.org>
* font-lock.el (lisp-font-lock-keywords-2): Add missing CL style
lambda list constructs (&key etc.).
* lisp-mode.el (lisp-function-and-type-regexp): Recognize defun*
as well as defun.
| author | Didier Verna <didier@xemacs.org> |
|---|---|
| date | Wed, 07 Apr 2010 14:38:41 +0200 |
| parents | 2e528066e2fc |
| children | 308d34e9f07d |
| rev | line source |
|---|---|
| 2510 | 1 ;;; register.el --- register commands for Emacs |
| 428 | 2 |
| 3 ;; Copyright (C) 1985, 1993, 1994, 1997 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Maintainer: FSF | |
| 6 ;; Keywords: internal, dumped | |
| 7 | |
| 8 ;; This file is part of XEmacs. | |
| 9 | |
| 10 ;; XEmacs is free software; you can redistribute it and/or modify it | |
| 11 ;; under the terms of the GNU General Public License as published by | |
| 12 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 13 ;; any later version. | |
| 14 | |
| 15 ;; XEmacs is distributed in the hope that it will be useful, but | |
| 16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 ;; General Public License for more details. | |
| 19 | |
| 20 ;; You should have received a copy of the GNU General Public License | |
| 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
| 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 23 ;; 02111-1307, USA. | |
| 24 | |
| 2510 | 25 ;;; Synched up with: FSF 21.3 |
| 428 | 26 |
| 27 ;;; Commentary: | |
| 28 | |
| 29 ;; This file is dumped with XEmacs. | |
| 30 | |
| 31 ;; This package of functions emulates and somewhat extends the venerable | |
| 32 ;; TECO's `register' feature, which permits you to save various useful | |
| 33 ;; pieces of buffer state to named variables. The entry points are | |
| 34 ;; documented in the Emacs user's manual. | |
| 35 | |
| 36 ;;; Code: | |
| 37 | |
| 38 (defvar register-alist nil | |
| 39 "Alist of elements (NAME . CONTENTS), one for each Emacs register. | |
| 40 NAME is a character (a number). CONTENTS is a string, number, marker or list. | |
| 41 A list of strings represents a rectangle. | |
| 42 A list of the form (file . NAME) represents the file named NAME. | |
| 43 A list of the form (file-query NAME POSITION) represents position POSITION | |
| 44 in the file named NAME, but query before visiting it. | |
| 45 A list of the form (WINDOW-CONFIGURATION POSITION) | |
| 46 represents a saved window configuration plus a saved value of point. | |
| 47 A list of the form (FRAME-CONFIGURATION POSITION) | |
| 48 represents a saved frame configuration plus a saved value of point.") | |
| 49 | |
| 50 (defun get-register (reg) | |
| 51 "Return contents of Emacs register named REG, or nil if none." | |
| 52 (cdr (assq reg register-alist))) | |
| 53 | |
| 54 (defun set-register (register value) | |
| 55 "Set contents of Emacs register named REGISTER to VALUE. Returns VALUE. | |
| 56 See the documentation of the variable `register-alist' for possible VALUE." | |
| 57 (let ((aelt (assq register register-alist))) | |
| 58 (if aelt | |
| 59 (setcdr aelt value) | |
| 2510 | 60 (push (cons register value) register-alist)) |
| 428 | 61 value)) |
| 62 | |
| 63 (defun point-to-register (register &optional arg) | |
| 64 "Store current location of point in register REGISTER. | |
| 65 With prefix argument, store current frame configuration. | |
| 66 Use \\[jump-to-register] to go to that location or restore that configuration. | |
| 67 Argument is a character, naming the register." | |
| 68 (interactive "cPoint to register: \nP") | |
| 2510 | 69 ;; Turn the marker into a file-ref if the buffer is killed. |
| 70 (add-hook 'kill-buffer-hook 'register-swap-out nil t) | |
| 428 | 71 (set-register register |
| 72 (if arg (list (current-frame-configuration) (point-marker)) | |
| 73 (point-marker)))) | |
| 74 | |
| 75 (defun window-configuration-to-register (register &optional arg) | |
| 76 "Store the window configuration of the selected frame in register REGISTER. | |
| 77 Use \\[jump-to-register] to restore the configuration. | |
| 78 Argument is a character, naming the register." | |
| 79 (interactive "cWindow configuration to register: \nP") | |
| 80 ;; current-window-configuration does not include the value | |
| 81 ;; of point in the current buffer, so record that separately. | |
| 82 (set-register register (list (current-window-configuration) (point-marker)))) | |
| 83 | |
| 84 (defun frame-configuration-to-register (register &optional arg) | |
| 85 "Store the window configuration of all frames in register REGISTER. | |
| 86 Use \\[jump-to-register] to restore the configuration. | |
| 87 Argument is a character, naming the register." | |
| 88 (interactive "cFrame configuration to register: \nP") | |
| 89 ;; current-frame-configuration does not include the value | |
| 90 ;; of point in the current buffer, so record that separately. | |
| 91 (set-register register (list (current-frame-configuration) (point-marker)))) | |
| 92 | |
| 93 (defalias 'register-to-point 'jump-to-register) | |
| 94 (defun jump-to-register (register &optional delete) | |
| 95 "Move point to location stored in a register. | |
| 96 If the register contains a file name, find that file. | |
| 97 \(To put a file name in a register, you must use `set-register'.) | |
| 98 If the register contains a window configuration (one frame) or a frame | |
| 99 configuration (all frames), restore that frame or all frames accordingly. | |
| 100 First argument is a character, naming the register. | |
| 101 Optional second arg non-nil (interactively, prefix argument) says to | |
| 102 delete any existing frames that the frame configuration doesn't mention. | |
| 103 \(Otherwise, these frames are iconified.)" | |
| 104 (interactive "cJump to register: \nP") | |
| 105 (let ((val (get-register register))) | |
| 106 (cond | |
| 107 ((and (consp val) (frame-configuration-p (car val))) | |
| 108 (set-frame-configuration (car val) (not delete)) | |
| 109 (goto-char (cadr val))) | |
| 110 ((and (consp val) (window-configuration-p (car val))) | |
| 111 (set-window-configuration (car val)) | |
| 112 (goto-char (cadr val))) | |
| 113 ((markerp val) | |
| 114 (or (marker-buffer val) | |
| 115 (error "That register's buffer no longer exists")) | |
| 116 (switch-to-buffer (marker-buffer val)) | |
| 117 (goto-char val)) | |
| 118 ((and (consp val) (eq (car val) 'file)) | |
| 119 (find-file (cdr val))) | |
| 120 ((and (consp val) (eq (car val) 'file-query)) | |
| 121 (or (find-buffer-visiting (nth 1 val)) | |
| 122 (y-or-n-p (format "Visit file %s again? " (nth 1 val))) | |
| 123 (error "Register access aborted")) | |
| 124 (find-file (nth 1 val)) | |
| 125 (goto-char (nth 2 val))) | |
| 126 (t | |
| 127 (error "Register doesn't contain a buffer position or configuration"))))) | |
| 128 | |
| 129 (defun register-swap-out () | |
| 2510 | 130 "Turn markers into file-query references when a buffer is killed." |
| 428 | 131 (and buffer-file-name |
| 2510 | 132 (dolist (elem register-alist) |
| 133 (and (markerp (cdr elem)) | |
| 134 (eq (marker-buffer (cdr elem)) (current-buffer)) | |
| 135 (setcdr elem | |
| 136 (list 'file-query | |
| 137 buffer-file-name | |
| 138 (marker-position (cdr elem)))))))) | |
| 428 | 139 |
| 140 (defun number-to-register (number register) | |
| 141 "Store a number in a register. | |
| 142 Two args, NUMBER and REGISTER (a character, naming the register). | |
| 143 If NUMBER is nil, a decimal number is read from the buffer starting | |
| 144 at point, and point moves to the end of that number. | |
| 145 Interactively, NUMBER is the prefix arg (none means nil)." | |
| 146 (interactive "P\ncNumber to register: ") | |
| 2510 | 147 (set-register register |
| 428 | 148 (if number |
| 149 (prefix-numeric-value number) | |
| 150 (if (looking-at "\\s-*-?[0-9]+") | |
| 151 (progn | |
| 152 (goto-char (match-end 0)) | |
| 153 (string-to-int (match-string 0))) | |
| 154 0)))) | |
| 155 | |
| 156 (defun increment-register (number register) | |
| 157 "Add NUMBER to the contents of register REGISTER. | |
| 158 Interactively, NUMBER is the prefix arg." | |
| 159 (interactive "p\ncIncrement register: ") | |
| 160 (or (numberp (get-register register)) | |
| 161 (error "Register does not contain a number")) | |
| 162 (set-register register (+ number (get-register register)))) | |
| 163 | |
| 164 (defun view-register (register) | |
| 165 "Display what is contained in register named REGISTER. | |
| 166 The Lisp value REGISTER is a character." | |
| 167 (interactive "cView register: ") | |
| 168 (let ((val (get-register register))) | |
| 169 (if (null val) | |
| 170 (message "Register %s is empty" (single-key-description register)) | |
| 171 (with-output-to-temp-buffer "*Output*" | |
| 2510 | 172 (describe-register-1 register t))))) |
| 173 | |
| 174 (defun list-registers () | |
| 175 "Display a list of nonempty registers saying briefly what they contain." | |
| 176 (interactive) | |
| 177 (let ((list (copy-sequence register-alist))) | |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3288
diff
changeset
|
178 (setq list (sort* list #'< :key #'car)) |
| 2510 | 179 (with-output-to-temp-buffer "*Output*" |
| 180 (dolist (elt list) | |
| 181 (when (get-register (car elt)) | |
| 182 (describe-register-1 (car elt)) | |
| 183 (terpri)))))) | |
| 428 | 184 |
| 2510 | 185 (defun describe-register-1 (register &optional verbose) |
| 186 (princ "Register ") | |
| 187 (princ (single-key-description register)) | |
| 188 (princ " contains ") | |
| 189 (let ((val (get-register register))) | |
| 190 (cond | |
| 191 ((numberp val) | |
| 192 (princ val)) | |
| 428 | 193 |
| 2510 | 194 ((markerp val) |
| 195 (let ((buf (marker-buffer val))) | |
| 196 (if (null buf) | |
| 197 (princ "a marker in no buffer") | |
| 198 (princ "a buffer position:\n buffer ") | |
| 199 (princ (buffer-name buf)) | |
| 200 (princ ", position ") | |
| 201 (princ (marker-position val))))) | |
| 428 | 202 |
| 2510 | 203 ((and (consp val) (window-configuration-p (car val))) |
| 204 (princ "a window configuration.")) | |
| 205 | |
| 206 ((and (consp val) (frame-configuration-p (car val))) | |
| 207 (princ "a frame configuration.")) | |
| 208 | |
| 209 ((and (consp val) (eq (car val) 'file)) | |
| 210 (princ "the file ") | |
| 211 (prin1 (cdr val)) | |
| 212 (princ ".")) | |
| 428 | 213 |
| 2510 | 214 ((and (consp val) (eq (car val) 'file-query)) |
| 215 (princ "a file-query reference:\n file ") | |
| 216 (prin1 (car (cdr val))) | |
| 217 (princ ",\n position ") | |
| 218 (princ (car (cdr (cdr val)))) | |
| 219 (princ ".")) | |
| 428 | 220 |
| 2510 | 221 ((consp val) |
| 222 (if verbose | |
| 223 (progn | |
| 224 (princ "the rectangle:\n") | |
| 225 (while val | |
| 226 (princ " ") | |
| 227 (princ (car val)) | |
| 228 (terpri) | |
| 229 (setq val (cdr val)))) | |
| 230 (princ "a rectangle starting with ") | |
| 231 (princ (car val)))) | |
| 428 | 232 |
| 2510 | 233 ((stringp val) |
| 3288 | 234 ;; XEmacs change: we don't have remove-list-of-text-properties |
| 235 (set-text-properties 0 (length val) nil val) | |
| 2510 | 236 (if verbose |
| 237 (progn | |
| 238 (princ "the text:\n") | |
| 239 (princ val)) | |
| 240 (cond | |
| 241 ;; Extract first N characters starting with first non-whitespace. | |
| 242 ((string-match (format "[^ \t\n].\\{,%d\\}" | |
| 243 ;; Deduct 6 for the spaces inserted below. | |
| 244 (min 20 (max 0 (- (window-width) 6)))) | |
| 245 val) | |
| 246 (princ "text starting with\n ") | |
| 247 (princ (match-string 0 val))) | |
| 248 ((string-match "^[ \t\n]+$" val) | |
| 249 (princ "whitespace")) | |
| 428 | 250 (t |
| 2510 | 251 (princ "the empty string"))))) |
| 252 (t | |
| 253 (princ "Garbage:\n") | |
| 254 (if verbose (prin1 val)))))) | |
| 428 | 255 |
| 256 (defun insert-register (register &optional arg) | |
| 257 "Insert contents of register REGISTER. (REGISTER is a character.) | |
| 258 Normally puts point before and mark after the inserted text. | |
| 259 If optional second arg is non-nil, puts mark before and point after. | |
| 260 Interactively, second arg is non-nil if prefix arg is supplied." | |
| 261 (interactive "*cInsert register: \nP") | |
| 262 (push-mark) | |
| 263 (let ((val (get-register register))) | |
| 264 (cond | |
| 265 ((consp val) | |
| 266 (insert-rectangle val)) | |
| 267 ((stringp val) | |
| 2696 | 268 (insert val)) |
| 428 | 269 ((numberp val) |
| 270 (princ val (current-buffer))) | |
| 271 ((and (markerp val) (marker-position val)) | |
| 272 (princ (marker-position val) (current-buffer))) | |
| 273 (t | |
| 274 (error "Register does not contain text")))) | |
| 275 ;; XEmacs: don't activate the region. It's annoying. | |
| 276 (if (not arg) (exchange-point-and-mark t))) | |
| 277 | |
| 278 (defun copy-to-register (register start end &optional delete-flag) | |
| 279 "Copy region into register REGISTER. With prefix arg, delete as well. | |
| 280 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. | |
| 281 START and END are buffer positions indicating what to copy." | |
| 282 (interactive "cCopy to register: \nr\nP") | |
| 283 (set-register register (buffer-substring start end)) | |
| 284 (if delete-flag (delete-region start end))) | |
| 285 | |
| 286 (defun append-to-register (register start end &optional delete-flag) | |
| 287 "Append region to text in register REGISTER. | |
| 288 With prefix arg, delete as well. | |
| 289 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. | |
| 290 START and END are buffer positions indicating what to append." | |
| 291 (interactive "cAppend to register: \nr\nP") | |
| 292 (or (stringp (get-register register)) | |
| 293 (error "Register does not contain text")) | |
| 294 (set-register register (concat (get-register register) | |
| 295 (buffer-substring start end))) | |
| 296 (if delete-flag (delete-region start end))) | |
| 297 | |
| 298 (defun prepend-to-register (register start end &optional delete-flag) | |
| 299 "Prepend region to text in register REGISTER. | |
| 300 With prefix arg, delete as well. | |
| 301 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. | |
| 302 START and END are buffer positions indicating what to prepend." | |
| 303 (interactive "cPrepend to register: \nr\nP") | |
| 304 (or (stringp (get-register register)) | |
| 305 (error "Register does not contain text")) | |
| 306 (set-register register (concat (buffer-substring start end) | |
| 307 (get-register register))) | |
| 308 (if delete-flag (delete-region start end))) | |
| 309 | |
| 310 (defun copy-rectangle-to-register (register start end &optional delete-flag) | |
| 311 "Copy rectangular region into register REGISTER. | |
| 312 With prefix arg, delete as well. | |
| 313 Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. | |
| 314 START and END are buffer positions giving two corners of rectangle." | |
| 315 (interactive "cCopy rectangle to register: \nr\nP") | |
| 316 (set-register register | |
| 317 (if delete-flag | |
| 318 (delete-extract-rectangle start end) | |
| 319 (extract-rectangle start end)))) | |
| 320 | |
| 321 ;;; register.el ends here |
