comparison lisp/menu-bar.el @ 8767:441af4b664ac

(yank-menu): New variable; kill-ring in menu format. (menu-bar-update-yank-menu, menu-bar-select-yank): New function.
author Karl Heuer <kwzh@gnu.org>
date Thu, 15 Sep 1994 22:16:49 +0000
parents fcc070bca96d
children 573c8013896b
comparison
equal deleted inserted replaced
8766:116e1882576b 8767:441af4b664ac
103 103
104 (define-key menu-bar-edit-menu [separator-edit] 104 (define-key menu-bar-edit-menu [separator-edit]
105 '("--")) 105 '("--"))
106 106
107 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region)) 107 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
108 (define-key menu-bar-edit-menu [choose-next-paste] 108
109 '("Choose Next Paste >" . mouse-menu-choose-yank)) 109 (define-key menu-bar-edit-menu [paste] '("Paste most recent" . yank))
110 (define-key menu-bar-edit-menu [paste] '("Paste" . yank)) 110
111 (defvar yank-menu (cons "Select Yank" nil))
112 (fset 'yank-menu (cons 'keymap yank-menu))
113 (define-key menu-bar-edit-menu [select-paste] '("Select and Paste" . yank-menu))
111 (define-key menu-bar-edit-menu [copy] '("Copy" . kill-ring-save)) 114 (define-key menu-bar-edit-menu [copy] '("Copy" . kill-ring-save))
112 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region)) 115 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
113 (define-key menu-bar-edit-menu [undo] '("Undo" . undo)) 116 (define-key menu-bar-edit-menu [undo] '("Undo" . undo))
114 117
115 (put 'fill-region 'menu-enable 'mark-active) 118 (put 'fill-region 'menu-enable 'mark-active)
116 (put 'kill-region 'menu-enable 'mark-active) 119 (put 'kill-region 'menu-enable 'mark-active)
117 (put 'kill-ring-save 'menu-enable 'mark-active) 120 (put 'kill-ring-save 'menu-enable 'mark-active)
118 (put 'yank 'menu-enable '(x-selection-exists-p)) 121 (put 'yank 'menu-enable '(x-selection-exists-p))
122 (put 'yank-menu 'menu-enable '(cdr yank-menu))
119 (put 'delete-region 'menu-enable 'mark-active) 123 (put 'delete-region 'menu-enable 'mark-active)
120 (put 'undo 'menu-enable '(if (eq last-command 'undo) 124 (put 'undo 'menu-enable '(if (eq last-command 'undo)
121 pending-undo-list 125 pending-undo-list
122 (consp buffer-undo-list))) 126 (consp buffer-undo-list)))
123 (put 'query-replace 'menu-enable (not buffer-read-only)) 127 (put 'query-replace 'menu-enable (not buffer-read-only))
230 (and (boundp 'pending-undo-list) 234 (and (boundp 'pending-undo-list)
231 pending-undo-list) 235 pending-undo-list)
232 buffer-undo-list))) 236 buffer-undo-list)))
233 237
234 (defvar yank-menu-length 100 238 (defvar yank-menu-length 100
235 "*Maximum length of an item in the menu for \ 239 "*Maximum length to display in the yank-menu.")
236 \\[mouse-menu-choose-yank].") 240
237 241 (defun menu-bar-update-yank-menu (string old)
238 (defun mouse-menu-choose-yank (event) 242 (let ((front (car (cdr yank-menu)))
239 "Pop up a menu of the kill-ring for selection with the mouse. 243 (menu-string (if (<= (length string) yank-menu-length)
240 The kill-ring-yank-pointer is moved to the selected element. 244 string
241 A subsequent \\[yank] yanks the choice just selected." 245 (substring string 0 yank-menu-length))))
242 (interactive "e") 246 ;; If we're supposed to be extending an existing string, and that
243 (let* ((count 0) 247 ;; string really is at the front of the menu, then update it in place.
244 (menu (mapcar (lambda (string) 248 (if (and old (or (eq old (car front))
245 (if (> (length string) yank-menu-length) 249 (string= old (car front))))
246 (setq string (substring string
247 0 yank-menu-length)))
248 (prog1 (cons string count)
249 (setq count (1+ count))))
250 kill-ring))
251 (arg (x-popup-menu event
252 (list "Yank Menu"
253 (cons "Choose Next Yank" menu)))))
254 ;; A mouse click outside the menu returns nil.
255 ;; Avoid a confusing error from passing nil to rotate-yank-pointer.
256 ;; XXX should this perhaps do something other than simply return? -rm
257 (if arg
258 (progn 250 (progn
259 ;; We don't use `rotate-yank-pointer' because we want to move 251 (setcar front string)
260 ;; relative to the beginning of kill-ring, not the current 252 (setcar (cdr front) menu-string))
261 ;; position. Also, that would ask for any new X selection and 253 (setcdr yank-menu
262 ;; thus change the list of items the user just chose from, which 254 (cons
263 ;; would be highly confusing. 255 (cons string (cons menu-string 'menu-bar-select-yank))
264 (setq kill-ring-yank-pointer (nthcdr arg kill-ring)) 256 (cdr yank-menu)))))
265 (if (interactive-p) 257 (if (> (length (cdr yank-menu)) kill-ring-max)
266 (message "The next yank will insert the selected text.") 258 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
267 (current-kill 0)))))) 259
268 (put 'mouse-menu-choose-yank 'menu-enable 'kill-ring) 260 (defun menu-bar-select-yank ()
261 (interactive "*")
262 (push-mark (point))
263 (insert last-command-event))
269 264
270 (define-key global-map [menu-bar buffer] '("Buffers" . menu-bar-buffers)) 265 (define-key global-map [menu-bar buffer] '("Buffers" . menu-bar-buffers))
271 266
272 (defalias 'menu-bar-buffers (make-sparse-keymap "Buffers")) 267 (defalias 'menu-bar-buffers (make-sparse-keymap "Buffers"))
273 268