329 |
;; Accepts as macro names: strings and vectors. |
;; Accepts as macro names: strings and vectors. |
330 |
;; strings must be strings of characters; vectors must be vectors of keys |
;; strings must be strings of characters; vectors must be vectors of keys |
331 |
;; in canonic form. The canonic form is essentially the form used in XEmacs |
;; in canonic form. The canonic form is essentially the form used in XEmacs |
332 |
|
;; More general definitions are inherited by more specific scopes: |
333 |
|
;; global->major mode->buffer. More specific definitions override more general |
334 |
(defun viper-record-kbd-macro (macro-name state macro-body &optional scope) |
(defun viper-record-kbd-macro (macro-name state macro-body &optional scope) |
335 |
"Record a Vi macro. Can be used in `.viper' file to define permanent macros. |
"Record a Vi macro. Can be used in `.viper' file to define permanent macros. |
336 |
MACRO-NAME is a string of characters or a vector of keys. STATE is |
MACRO-NAME is a string of characters or a vector of keys. STATE is |
453 |
(list (list (cons scope nil)) nil (cons t nil)))))) |
(list (list (cons scope nil)) nil (cons t nil)))))) |
454 |
(setq old-elt (assoc macro-name (eval macro-alist-var))) |
(setq old-elt (assoc macro-name (eval macro-alist-var))) |
455 |
|
|
456 |
(if (null old-elt) |
(if (null old-elt) |
457 |
(progn |
(progn |
458 |
;; insert new-elt in macro-alist-var and keep the list sorted |
;; insert new-elt in macro-alist-var and keep the list sorted |
459 |
(define-key |
(define-key |
460 |
keymap |
keymap |
461 |
(vector (viper-key-to-emacs-key (aref macro-name 0))) |
(vector (viper-key-to-emacs-key (aref macro-name 0))) |
462 |
'viper-exec-mapped-kbd-macro) |
'viper-exec-mapped-kbd-macro) |
463 |
(setq lis (eval macro-alist-var)) |
(setq lis (eval macro-alist-var)) |
464 |
(while (and lis (string< (viper-array-to-string (car (car lis))) |
(while (and lis (string< (viper-array-to-string (car (car lis))) |
465 |
(viper-array-to-string macro-name))) |
(viper-array-to-string macro-name))) |
466 |
(setq lis2 (cons (car lis) lis2)) |
(setq lis2 (cons (car lis) lis2)) |
467 |
(setq lis (cdr lis))) |
(setq lis (cdr lis))) |
468 |
|
|
469 |
(setq lis2 (reverse lis2)) |
(setq lis2 (reverse lis2)) |
470 |
(set macro-alist-var (append lis2 (cons new-elt lis))) |
(set macro-alist-var (append lis2 (cons new-elt lis))) |
471 |
(setq old-elt new-elt))) |
(setq old-elt new-elt))) |
472 |
(setq old-sub-elt |
(setq old-sub-elt |
473 |
(cond ((eq scope t) (viper-kbd-global-pair old-elt)) |
(cond ((eq scope t) (viper-kbd-global-pair old-elt)) |
474 |
((symbolp scope) (assoc scope (viper-kbd-mode-alist old-elt))) |
((symbolp scope) (assoc scope (viper-kbd-mode-alist old-elt))) |
486 |
|
|
487 |
|
|
488 |
;; macro name must be a vector of viper-style keys |
;; macro name must be a vector of viper-style keys |
489 |
|
;; viper-unrecord-kbd-macro doesn't have scope. Macro definitions are inherited |
490 |
|
;; from global -> major mode -> buffer |
491 |
|
;; More specific definition overrides more general |
492 |
|
;; Can't unrecord definition for more specific, if a more general definition is |
493 |
|
;; in effect |
494 |
(defun viper-unrecord-kbd-macro (macro-name state) |
(defun viper-unrecord-kbd-macro (macro-name state) |
495 |
"Delete macro MACRO-NAME from Viper STATE. |
"Delete macro MACRO-NAME from Viper STATE. |
496 |
MACRO-NAME must be a vector of viper-style keys. This command is used by Viper |
MACRO-NAME must be a vector of viper-style keys. This command is used by Viper |
553 |
(setq macro-pair mode-mapping) |
(setq macro-pair mode-mapping) |
554 |
(message "%S is unmapped for %s in %S" |
(message "%S is unmapped for %s in %S" |
555 |
(viper-display-macro macro-name) state-name major-mode)) |
(viper-display-macro macro-name) state-name major-mode)) |
556 |
((cdr (setq macro-pair (viper-kbd-global-pair macro-entry))) |
((cdr (setq macro-pair global-mapping)) |
557 |
(message |
(message |
558 |
"Global mapping for %S in %s is removed" |
"Global mapping for %S in %s is removed" |
559 |
(viper-display-macro macro-name) state-name)) |
(viper-display-macro macro-name) state-name)) |
567 |
(progn |
(progn |
568 |
(set macro-alist-var (delq macro-entry (eval macro-alist-var))) |
(set macro-alist-var (delq macro-entry (eval macro-alist-var))) |
569 |
(if (viper-can-release-key (aref macro-name 0) |
(if (viper-can-release-key (aref macro-name 0) |
570 |
(eval macro-alist-var)) |
(eval macro-alist-var)) |
571 |
(define-key |
(define-key |
572 |
keymap |
keymap |
573 |
(vector (viper-key-to-emacs-key (aref macro-name 0))) |
(vector (viper-key-to-emacs-key (aref macro-name 0))) |