Mercurial > emacs
comparison lisp/emacs-lisp/easymenu.el @ 21807:c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
argument. Now it works also if you repeat an identical call to
easy-menu-define-key.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 28 Apr 1998 20:03:07 +0000 |
parents | 38a6d62cddb9 |
children | aa1d105f0d67 |
comparison
equal
deleted
inserted
replaced
21806:d17bf0e8a170 | 21807:c62197b13ece |
---|---|
272 ;; don't insert, only delete. | 272 ;; don't insert, only delete. |
273 ;; Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil | 273 ;; Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil |
274 ;; put binding before BEFORE in MENU, otherwise if binding is already | 274 ;; put binding before BEFORE in MENU, otherwise if binding is already |
275 ;; present in MENU, just change it, otherwise put it last in MENU. | 275 ;; present in MENU, just change it, otherwise put it last in MENU. |
276 (let ((inserted (null item)) ; Fake already inserted. | 276 (let ((inserted (null item)) ; Fake already inserted. |
277 done) | 277 tail done) |
278 (while (not done) | 278 (while (not done) |
279 (cond | 279 (cond |
280 ((or (setq done (or (null (cdr menu)) (keymapp (cdr menu)))) | 280 ((or (setq done (or (null (cdr menu)) (keymapp (cdr menu)))) |
281 (and before (equal (car-safe (cadr menu)) before))) | 281 (and before (equal (car-safe (cadr menu)) before))) |
282 ;; If key is nil, stop here, otherwise keep going past the | 282 ;; If key is nil, stop here, otherwise keep going past the |
284 ;; later. | 284 ;; later. |
285 (if (null key) (setq done t)) | 285 (if (null key) (setq done t)) |
286 (unless inserted ; Don't insert more than once. | 286 (unless inserted ; Don't insert more than once. |
287 (setcdr menu (cons (cons key item) (cdr menu))) | 287 (setcdr menu (cons (cons key item) (cdr menu))) |
288 (setq inserted t) | 288 (setq inserted t) |
289 (setq menu (cdr menu)))) | 289 (setq menu (cdr menu))) |
290 (setq menu (cdr menu))) | |
290 ((and key (equal (car-safe (cadr menu)) key)) | 291 ((and key (equal (car-safe (cadr menu)) key)) |
291 (if (and (or inserted ; Already inserted or | 292 (if (or inserted ; Already inserted or |
292 before) ; wanted elsewhere and | 293 (and before ; wanted elsewhere and |
293 (or (not (setq done ; not the last in this keymap. | 294 (setq tail (cddr menu)) ; not last item and not |
294 (or (null (cddr menu)) | 295 (not (keymapp tail)) |
295 (keymapp (cddr menu))))) | 296 (not (equal (car-safe (car tail)) before)))) ; in position |
296 inserted)) | |
297 ;; The contorted logic above, guarantees `done' has been computed. | |
298 (setcdr menu (cddr menu)) ; Remove item. | 297 (setcdr menu (cddr menu)) ; Remove item. |
299 (setcdr (cadr menu) item) ; Change item. | 298 (setcdr (cadr menu) item) ; Change item. |
300 (setq inserted t)))) | 299 (setq inserted t) |
301 (setq menu (cdr menu))))) | 300 (setq menu (cdr menu)))) |
302 | 301 (t (setq menu (cdr menu))))))) |
302 | |
303 (defun easy-menu-always-true (x) | 303 (defun easy-menu-always-true (x) |
304 ;; Return true if X never evaluates to nil. | 304 ;; Return true if X never evaluates to nil. |
305 (if (consp x) (and (eq (car x) 'quote) (cadr x)) | 305 (if (consp x) (and (eq (car x) 'quote) (cadr x)) |
306 (or (eq x t) (not (symbolp x))))) | 306 (or (eq x t) (not (symbolp x))))) |
307 | 307 |