Mercurial > emacs
comparison lisp/vcursor.el @ 91040:14c4a6aac623
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 866-879)
- Merge multi-tty branch
- Update from CVS
- Merge from emacs--rel--22
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-257
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 11 Oct 2007 16:14:00 +0000 |
parents | f55f9811f5d7 80b69e6b234d |
children | 606f2d163a64 |
comparison
equal
deleted
inserted
replaced
91039:eefadc1e1d5e | 91040:14c4a6aac623 |
---|---|
266 ;; in the usual way, e.g. | 266 ;; in the usual way, e.g. |
267 ;; (global-set-key [f14] vcursor-map) | 267 ;; (global-set-key [f14] vcursor-map) |
268 ;; and also as usual \C-h in this map will list the key definitions, which | 268 ;; and also as usual \C-h in this map will list the key definitions, which |
269 ;; are designed to be easy to remember. | 269 ;; are designed to be easy to remember. |
270 ;; | 270 ;; |
271 ;; A special feature is provided by (vcursor-toggle-vcursor-map), bound | 271 ;; A special feature is provided by (vcursor-use-vcursor-map), bound |
272 ;; to t in that keymap. With this in effect, the main keymap | 272 ;; to t in that keymap. With this in effect, the main keymap |
273 ;; is overridden by the vcursor map, so keys like \C-p and so on | 273 ;; is overridden by the vcursor map, so keys like \C-p and so on |
274 ;; move the vcursor instead. Remember how to turn it off (type t), | 274 ;; move the vcursor instead. Remember how to turn it off (type t), |
275 ;; or you are in serious trouble! Note that the cursor keys are not | 275 ;; or you are in serious trouble! Note that the cursor keys are not |
276 ;; bound by default in this keymap and will continue to move the | 276 ;; bound by default in this keymap and will continue to move the |
334 (t (:inverse-video t :underline t))) | 334 (t (:inverse-video t :underline t))) |
335 "Face for the virtual cursor." | 335 "Face for the virtual cursor." |
336 :group 'vcursor) | 336 :group 'vcursor) |
337 | 337 |
338 (defcustom vcursor-auto-disable nil | 338 (defcustom vcursor-auto-disable nil |
339 "*If non-nil, disable the virtual cursor after use. | 339 "If non-nil, disable the virtual cursor after use. |
340 Any non-vcursor command will force `vcursor-disable' to be called. | 340 Any non-vcursor command will force `vcursor-disable' to be called. |
341 If non-nil but not t, just make sure copying is toggled off, but don't | 341 If non-nil but not t, just make sure copying is toggled off, but don't |
342 disable the vcursor." | 342 disable the vcursor." |
343 :type '(choice (const t) (const nil) (const copy)) | 343 :type '(choice (const t) (const nil) (const copy)) |
344 :group 'vcursor) | 344 :group 'vcursor) |
345 | 345 |
346 (defcustom vcursor-modifiers (list 'control 'shift) | 346 (defcustom vcursor-modifiers (list 'control 'shift) |
347 "*A list of modifiers that are used to define vcursor key bindings." | 347 "A list of modifiers that are used to define vcursor key bindings." |
348 :type '(repeat symbol) | 348 :type '(repeat symbol) |
349 :group 'vcursor) | 349 :group 'vcursor) |
350 | 350 |
351 ;; Needed for defcustom, must be up here | 351 ;; Needed for defcustom, must be up here |
352 (defun vcursor-cs-binding (base &optional meta) | 352 (defun vcursor-cs-binding (base &optional meta) |
462 (global-set-key (vcursor-cs-binding "f9") 'vcursor-execute-key) | 462 (global-set-key (vcursor-cs-binding "f9") 'vcursor-execute-key) |
463 (global-set-key (vcursor-cs-binding "f10") 'vcursor-execute-command) | 463 (global-set-key (vcursor-cs-binding "f10") 'vcursor-execute-command) |
464 ))) | 464 ))) |
465 | 465 |
466 (defcustom vcursor-key-bindings nil | 466 (defcustom vcursor-key-bindings nil |
467 "*How to bind keys when vcursor is loaded. | 467 "How to bind keys when vcursor is loaded. |
468 If t, guess; if `xterm', use bindings suitable for an X terminal; if | 468 If t, guess; if `xterm', use bindings suitable for an X terminal; if |
469 `oemacs', use bindings which work on a PC with Oemacs. If nil, don't | 469 `oemacs', use bindings which work on a PC with Oemacs. If nil, don't |
470 define any key bindings. | 470 define any key bindings. |
471 | 471 |
472 Default is nil." | 472 Default is nil." |
474 :group 'vcursor | 474 :group 'vcursor |
475 :set 'vcursor-bind-keys | 475 :set 'vcursor-bind-keys |
476 :version "20.3") | 476 :version "20.3") |
477 | 477 |
478 (defcustom vcursor-interpret-input nil | 478 (defcustom vcursor-interpret-input nil |
479 "*If non-nil, input from the vcursor is treated as interactive input. | 479 "If non-nil, input from the vcursor is treated as interactive input. |
480 This will cause text insertion to be much slower. Note that no special | 480 This will cause text insertion to be much slower. Note that no special |
481 interpretation of strings is done: \"\C-x\" is a string of four | 481 interpretation of strings is done: \"\C-x\" is a string of four |
482 characters. The default is simply to copy strings." | 482 characters. The default is simply to copy strings." |
483 :type 'boolean | 483 :type 'boolean |
484 :group 'vcursor | 484 :group 'vcursor |
504 scrolling set this. It is used by the `vcursor-auto-disable' code.") | 504 scrolling set this. It is used by the `vcursor-auto-disable' code.") |
505 ;; could do some memq-ing with last-command instead, but this will | 505 ;; could do some memq-ing with last-command instead, but this will |
506 ;; automatically handle any new commands using the primitives. | 506 ;; automatically handle any new commands using the primitives. |
507 | 507 |
508 (defcustom vcursor-copy-flag nil | 508 (defcustom vcursor-copy-flag nil |
509 "*Non-nil means moving vcursor should copy characters moved over to point." | 509 "Non-nil means moving vcursor should copy characters moved over to point." |
510 :type 'boolean | 510 :type 'boolean |
511 :group 'vcursor) | 511 :group 'vcursor) |
512 | 512 |
513 (defvar vcursor-temp-goal-column nil | 513 (defvar vcursor-temp-goal-column nil |
514 "Keeps track of temporary goal columns for the virtual cursor.") | 514 "Keeps track of temporary goal columns for the virtual cursor.") |
515 | 515 |
516 (defvar vcursor-use-vcursor-map nil | 516 (defvar vcursor-map |
517 "Non-nil if the vcursor map is mapped directly onto the main keymap. | 517 (let ((map (make-sparse-keymap))) |
518 See `vcursor-toggle-vcursor-map'.") | 518 (define-key map "t" 'vcursor-use-vcursor-map) |
519 (make-variable-buffer-local 'vcursor-use-vcursor-map) | 519 |
520 | 520 (define-key map "\C-p" 'vcursor-previous-line) |
521 (defvar vcursor-map nil "Keymap for vcursor command.") | 521 (define-key map "\C-n" 'vcursor-next-line) |
522 (define-prefix-command 'vcursor-map) | 522 (define-key map "\C-b" 'vcursor-backward-char) |
523 | 523 (define-key map "\C-f" 'vcursor-forward-char) |
524 (define-key vcursor-map "t" 'vcursor-toggle-vcursor-map) | 524 |
525 | 525 (define-key map "\r" 'vcursor-disable) |
526 (define-key vcursor-map "\C-p" 'vcursor-previous-line) | 526 (define-key map " " 'vcursor-copy) |
527 (define-key vcursor-map "\C-n" 'vcursor-next-line) | 527 (define-key map "\C-y" 'vcursor-copy-word) |
528 (define-key vcursor-map "\C-b" 'vcursor-backward-char) | 528 (define-key map "\C-i" 'vcursor-toggle-copy) |
529 (define-key vcursor-map "\C-f" 'vcursor-forward-char) | 529 (define-key map "<" 'vcursor-beginning-of-buffer) |
530 | 530 (define-key map ">" 'vcursor-end-of-buffer) |
531 (define-key vcursor-map "\r" 'vcursor-disable) | 531 (define-key map "\M-v" 'vcursor-scroll-down) |
532 (define-key vcursor-map " " 'vcursor-copy) | 532 (define-key map "\C-v" 'vcursor-scroll-up) |
533 (define-key vcursor-map "\C-y" 'vcursor-copy-word) | 533 (define-key map "o" 'vcursor-other-window) |
534 (define-key vcursor-map "\C-i" 'vcursor-toggle-copy) | 534 (define-key map "g" 'vcursor-goto) |
535 (define-key vcursor-map "<" 'vcursor-beginning-of-buffer) | 535 (define-key map "x" 'vcursor-swap-point) |
536 (define-key vcursor-map ">" 'vcursor-end-of-buffer) | 536 (define-key map "\C-s" 'vcursor-isearch-forward) |
537 (define-key vcursor-map "\M-v" 'vcursor-scroll-down) | 537 (define-key map "\C-r" 'vcursor-isearch-backward) |
538 (define-key vcursor-map "\C-v" 'vcursor-scroll-up) | 538 (define-key map "\C-a" 'vcursor-beginning-of-line) |
539 (define-key vcursor-map "o" 'vcursor-other-window) | 539 (define-key map "\C-e" 'vcursor-end-of-line) |
540 (define-key vcursor-map "g" 'vcursor-goto) | 540 (define-key map "\M-w" 'vcursor-forward-word) |
541 (define-key vcursor-map "x" 'vcursor-swap-point) | 541 (define-key map "\M-b" 'vcursor-backward-word) |
542 (define-key vcursor-map "\C-s" 'vcursor-isearch-forward) | 542 (define-key map "\M-l" 'vcursor-copy-line) |
543 (define-key vcursor-map "\C-r" 'vcursor-isearch-backward) | 543 (define-key map "c" 'vcursor-compare-windows) |
544 (define-key vcursor-map "\C-a" 'vcursor-beginning-of-line) | 544 (define-key map "k" 'vcursor-execute-key) |
545 (define-key vcursor-map "\C-e" 'vcursor-end-of-line) | 545 (define-key map "\M-x" 'vcursor-execute-command) |
546 (define-key vcursor-map "\M-w" 'vcursor-forward-word) | 546 map) |
547 (define-key vcursor-map "\M-b" 'vcursor-backward-word) | 547 "Keymap for vcursor command.") |
548 (define-key vcursor-map "\M-l" 'vcursor-copy-line) | 548 ;; This seems unused, but it was done as part of define-prefix-command, |
549 (define-key vcursor-map "c" 'vcursor-compare-windows) | 549 ;; so let's keep it for now. |
550 (define-key vcursor-map "k" 'vcursor-execute-key) | 550 (fset 'vcursor-map vcursor-map) |
551 (define-key vcursor-map "\M-x" 'vcursor-execute-command) | |
552 | 551 |
553 ;; If vcursor-key-bindings is already set on loading, bind the keys now. | 552 ;; If vcursor-key-bindings is already set on loading, bind the keys now. |
554 ;; This hybrid way of doing it retains compatibility while allowing | 553 ;; This hybrid way of doing it retains compatibility while allowing |
555 ;; customize to work smoothly. | 554 ;; customize to work smoothly. |
556 (if vcursor-key-bindings | 555 (if vcursor-key-bindings |
714 not be visible otherwise, display it in another window." | 713 not be visible otherwise, display it in another window." |
715 | 714 |
716 (interactive) | 715 (interactive) |
717 (let ((buf (current-buffer)) (here (point)) (win (selected-window))) | 716 (let ((buf (current-buffer)) (here (point)) (win (selected-window))) |
718 (vcursor-goto) ; will disable the vcursor | 717 (vcursor-goto) ; will disable the vcursor |
719 (save-excursion | 718 (with-current-buffer buf |
720 (set-buffer buf) | |
721 (setq vcursor-window win) | 719 (setq vcursor-window win) |
722 (vcursor-move here))) | 720 (vcursor-move here))) |
723 ) | 721 ) |
724 | 722 |
725 (defun vcursor-scroll-up (&optional n) | 723 (defun vcursor-scroll-up (&optional n) |
799 | 797 |
800 This is called by most of the virtual-cursor copying commands to find | 798 This is called by most of the virtual-cursor copying commands to find |
801 out how much to copy." | 799 out how much to copy." |
802 | 800 |
803 (vcursor-check) | 801 (vcursor-check) |
804 (save-excursion | 802 (with-current-buffer (overlay-buffer vcursor-overlay) |
805 (set-buffer (overlay-buffer vcursor-overlay)) | |
806 (let ((start (goto-char (overlay-start vcursor-overlay)))) | 803 (let ((start (goto-char (overlay-start vcursor-overlay)))) |
807 (- (progn (apply func args) (point)) start))) | 804 (- (progn (apply func args) (point)) start))) |
808 ) | 805 ) |
809 | 806 |
810 ;; Make sure the virtual cursor is active. Unless arg is non-nil, | 807 ;; Make sure the virtual cursor is active. Unless arg is non-nil, |
814 ((and (overlayp vcursor-overlay) (overlay-start vcursor-overlay)) | 811 ((and (overlayp vcursor-overlay) (overlay-start vcursor-overlay)) |
815 t) | 812 t) |
816 (arg nil) | 813 (arg nil) |
817 (t (error "The virtual cursor is not active now"))) | 814 (t (error "The virtual cursor is not active now"))) |
818 ) | 815 ) |
816 | |
817 (define-minor-mode vcursor-use-vcursor-map | |
818 "Toggle the state of the vcursor key map. | |
819 When on, the keys defined in it are mapped directly on top of the main | |
820 keymap, allowing you to move the vcursor with ordinary motion keys. | |
821 An indication \"!VC\" appears in the mode list. The effect is | |
822 local to the current buffer. | |
823 Disabling the vcursor automatically turns this off." | |
824 :keymap vcursor-map | |
825 :lighter " !VC") | |
819 | 826 |
820 (defun vcursor-disable (&optional arg) | 827 (defun vcursor-disable (&optional arg) |
821 "Disable the virtual cursor. | 828 "Disable the virtual cursor. |
822 Next time you use it, it will start from point. | 829 Next time you use it, it will start from point. |
823 | 830 |
842 ((delete-window vcursor-window))) | 849 ((delete-window vcursor-window))) |
843 (cond | 850 (cond |
844 ((and arg (< (prefix-numeric-value arg) 0)) | 851 ((and arg (< (prefix-numeric-value arg) 0)) |
845 (vcursor-move (point)) | 852 (vcursor-move (point)) |
846 (setq vcursor-window (selected-window))) | 853 (setq vcursor-window (selected-window))) |
847 (vcursor-use-vcursor-map (vcursor-toggle-vcursor-map 0))) | 854 (vcursor-use-vcursor-map (vcursor-use-vcursor-map 0))) |
848 (setq vcursor-copy-flag nil) | 855 (setq vcursor-copy-flag nil) |
849 ) | 856 ) |
850 | 857 |
851 (defun vcursor-other-window (n &optional all-frames) | 858 (defun vcursor-other-window (n &optional all-frames) |
852 "Activate the virtual cursor in another window. | 859 "Activate the virtual cursor in another window. |
865 (save-excursion | 872 (save-excursion |
866 (save-window-excursion | 873 (save-window-excursion |
867 ;; We don't use fancy vcursor-find-window trickery, since we're | 874 ;; We don't use fancy vcursor-find-window trickery, since we're |
868 ;; quite happy to have the vcursor cycle back into the current | 875 ;; quite happy to have the vcursor cycle back into the current |
869 ;; window. | 876 ;; window. |
870 (let ((sw (selected-window)) | 877 (let ((win (vcursor-find-window nil nil (not all-frames)))) |
871 (win (vcursor-find-window nil nil (not all-frames)))) | |
872 (if win (select-window win)) | 878 (if win (select-window win)) |
873 ;; else start from here | 879 ;; else start from here |
874 (other-window n all-frames) | 880 (other-window n all-frames) |
875 (vcursor-disable -1)))) | 881 (vcursor-disable -1)))) |
876 ) | 882 ) |
889 If `compare-ignore-case' is non-nil, changes in case are also ignored." | 895 If `compare-ignore-case' is non-nil, changes in case are also ignored." |
890 (interactive "P") | 896 (interactive "P") |
891 ;; (vcursor-window-funcall 'compare-windows arg) | 897 ;; (vcursor-window-funcall 'compare-windows arg) |
892 (require 'compare-w) | 898 (require 'compare-w) |
893 (let* (p1 p2 maxp1 maxp2 b1 b2 w2 | 899 (let* (p1 p2 maxp1 maxp2 b1 b2 w2 |
894 success size | 900 success |
895 (opoint1 (point)) | 901 (opoint1 (point)) |
896 opoint2 | 902 opoint2 |
897 (skip-whitespace (if ignore-whitespace | 903 (skip-whitespace (if ignore-whitespace |
898 compare-windows-whitespace))) | 904 compare-windows-whitespace))) |
899 (setq p1 (point) b1 (current-buffer)) | 905 (setq p1 (point) b1 (current-buffer)) |
903 (save-excursion | 909 (save-excursion |
904 (vcursor-locate) | 910 (vcursor-locate) |
905 (setq p2 (point) b2 (current-buffer))) | 911 (setq p2 (point) b2 (current-buffer))) |
906 (setq opoint2 p2) | 912 (setq opoint2 p2) |
907 (setq maxp1 (point-max)) | 913 (setq maxp1 (point-max)) |
908 (save-excursion | 914 (with-current-buffer b2 |
909 (set-buffer b2) | |
910 (setq maxp2 (point-max))) | 915 (setq maxp2 (point-max))) |
911 | 916 |
912 (setq success t) | 917 (setq success t) |
913 (while success | 918 (while success |
914 (setq success nil) | 919 (setq success nil) |
919 ;; If both buffers have whitespace next to point, | 924 ;; If both buffers have whitespace next to point, |
920 ;; optionally skip over it. | 925 ;; optionally skip over it. |
921 | 926 |
922 (and skip-whitespace | 927 (and skip-whitespace |
923 (save-excursion | 928 (save-excursion |
924 (let (p1a p2a w1 w2 result1 result2) | 929 (let (p1a p2a result1 result2) |
925 (setq result1 | 930 (setq result1 |
926 (if (stringp skip-whitespace) | 931 (if (stringp skip-whitespace) |
927 (compare-windows-skip-whitespace opoint1) | 932 (compare-windows-skip-whitespace opoint1) |
928 (funcall skip-whitespace opoint1))) | 933 (funcall skip-whitespace opoint1))) |
929 (setq p1a (point)) | 934 (setq p1a (point)) |
1094 (defun vcursor-copy (arg) | 1099 (defun vcursor-copy (arg) |
1095 "Copy ARG characters from the virtual cursor position to point." | 1100 "Copy ARG characters from the virtual cursor position to point." |
1096 (interactive "p") | 1101 (interactive "p") |
1097 (vcursor-check) | 1102 (vcursor-check) |
1098 (vcursor-insert | 1103 (vcursor-insert |
1099 (save-excursion | 1104 (with-current-buffer (overlay-buffer vcursor-overlay) |
1100 (set-buffer (overlay-buffer vcursor-overlay)) | |
1101 (let* ((ostart (overlay-start vcursor-overlay)) | 1105 (let* ((ostart (overlay-start vcursor-overlay)) |
1102 (end (+ ostart arg))) | 1106 (end (+ ostart arg))) |
1103 (prog1 | 1107 (prog1 |
1104 (buffer-substring ostart end) | 1108 (buffer-substring ostart end) |
1105 (vcursor-move end))))) | 1109 (vcursor-move end))))) |
1124 (let* ((num (prefix-numeric-value arg)) | 1128 (let* ((num (prefix-numeric-value arg)) |
1125 (count (vcursor-get-char-count 'end-of-line num))) | 1129 (count (vcursor-get-char-count 'end-of-line num))) |
1126 (vcursor-copy (if (or (= count 0) arg) (1+ count) count))) | 1130 (vcursor-copy (if (or (= count 0) arg) (1+ count) count))) |
1127 ) | 1131 ) |
1128 | 1132 |
1129 (defun vcursor-toggle-vcursor-map (&optional force noredisp) | 1133 (define-obsolete-function-alias |
1130 "Toggle the state of the vcursor key map. | 1134 'vcursor-toggle-vcursor-map 'vcursor-use-vcursor-map "23.1") |
1131 When on, the keys defined in it are mapped directly on top of the main | |
1132 keymap, allowing you to move the vcursor with ordinary motion keys. | |
1133 An indication \"!VC\" appears in the mode list. The effect is | |
1134 local to the current buffer. | |
1135 With prefix FORCE, turn on, or off if it is 0. | |
1136 With NOREDISP, don't force redisplay. | |
1137 Disabling the vcursor automatically turns this off." | |
1138 (interactive "P") | |
1139 (let ((new (cond ((not force) (not vcursor-use-vcursor-map)) | |
1140 ((eq force 0) nil) | |
1141 (t)))) | |
1142 (or (eq new vcursor-use-vcursor-map) | |
1143 (progn | |
1144 (setq vcursor-use-vcursor-map new) | |
1145 (or (assq 'vcursor-use-vcursor-map minor-mode-map-alist) | |
1146 (setq minor-mode-map-alist | |
1147 (cons (cons 'vcursor-use-vcursor-map vcursor-map) | |
1148 minor-mode-map-alist))) | |
1149 (or (assq 'vcursor-use-vcursor-map minor-mode-alist) | |
1150 (setq minor-mode-alist | |
1151 (cons (list 'vcursor-use-vcursor-map " !VC") | |
1152 minor-mode-alist))) | |
1153 (or noredisp (redraw-display))))) | |
1154 ) | |
1155 | 1135 |
1156 (defun vcursor-post-command () | 1136 (defun vcursor-post-command () |
1157 (and vcursor-auto-disable (not vcursor-last-command) | 1137 (and vcursor-auto-disable (not vcursor-last-command) |
1158 vcursor-overlay | 1138 vcursor-overlay |
1159 (if (eq vcursor-auto-disable t) | 1139 (if (eq vcursor-auto-disable t) |
1164 | 1144 |
1165 (add-hook 'post-command-hook 'vcursor-post-command) | 1145 (add-hook 'post-command-hook 'vcursor-post-command) |
1166 | 1146 |
1167 (provide 'vcursor) | 1147 (provide 'vcursor) |
1168 | 1148 |
1169 ;;; arch-tag: cdfe1cdc-2c46-4046-88e4-ed57d20f7aca | 1149 ;; arch-tag: cdfe1cdc-2c46-4046-88e4-ed57d20f7aca |
1170 ;;; vcursor.el ends here | 1150 ;;; vcursor.el ends here |