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