comparison lisp/vcursor.el @ 22650:2809ce5a1a0a

Use defcustom to define faces. (vcursor-bind-keys): New function. (vcursor-key-bindings): Use vcursor-bind-keys for :set. (vcursor-cs-binding): Function to handle bindings, handles differences between Emacs and XEmacs. (vcursor-post-command): Handle vcursor-auto-disable non-nil and not t to toggle off copying.
author Richard M. Stallman <rms@gnu.org>
date Tue, 30 Jun 1998 07:05:40 +0000
parents 9861518505cb
children 12fca8181eca
comparison
equal deleted inserted replaced
22649:4934aaa2055c 22650:2809ce5a1a0a
1 ;;; vcursor.el --- manipulate an alternative ("virtual") cursor. 1 ;;; vcursor.el --- manipulate an alternative ("virtual") cursor.
2 2
3 ;; Copyright (C) 1994, 1996, 1998 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1996, 1998 Free Software Foundation, Inc.
4 4
5 ;; Author: Peter Stephenson <pws@ifh.de> 5 ;; Author: Peter Stephenson <pws@ibmth.df.unipi.it>
6 ;; Keywords: virtual cursor, display, copying 6 ;; Keywords: virtual cursor, display, copying
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
9 9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; GNU Emacs is free software; you can redistribute it and/or modify
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; Latest changes (1.6) 27 ;; Latest changes
28 ;; ==================== 28 ;; ==============
29 ;; 29 ;;
30 ;; - *IMPORTANT* vcursor-key-bindings is now nil by default, to avoid
31 ;; side-effects when the package is loaded. This means no keys are
32 ;; bound by default. Use customize to change it to t to restore
33 ;; the old behaviour. (If you do it by hand in .emacs, it
34 ;; must come before vcursor is loaded.)
35 ;; - You can alter the main variables and the vcursor face via
36 ;; M-x customize: go to the Editing group and find Vcursor.
37 ;; - vcursor-auto-disable can now be 'copy (actually any value not nil
38 ;; or t), which means that copying from the vcursor will be turned
39 ;; off after any operation not involving the vcursor, but the
40 ;; vcursor itself will be left alone.
41 ;; - should now work unmodified under XEmacs
30 ;; - works on dumb terminals with Emacs 19.29 and later 42 ;; - works on dumb terminals with Emacs 19.29 and later
31 ;; - new keymap vcursor-map for binding to a prefix key 43 ;; - new keymap vcursor-map for binding to a prefix key
32 ;; - vcursor-compare-windows substantially improved 44 ;; - vcursor-compare-windows substantially improved
33 ;; - vcursor-execute-{key,command} much better about using the 45 ;; - vcursor-execute-{key,command} much better about using the
34 ;; right keymaps and arranging for the correct windows to be used 46 ;; right keymaps and arranging for the correct windows to be used
44 ;; (special behaviour for the overlay property 56 ;; (special behaviour for the overlay property
45 ;; "before-string" must be implemented). Search for "dumb terminals" 57 ;; "before-string" must be implemented). Search for "dumb terminals"
46 ;; for more information. 58 ;; for more information.
47 ;; 59 ;;
48 ;; This is much easier to use than the instructions are to read. 60 ;; This is much easier to use than the instructions are to read.
49 ;; I suggest you simply load it and play around with holding down Ctrl 61 ;; First, you need to let vcursor define some keys: setting
50 ;; and Shift and pressing up, down, left, right, tab, return, and see 62 ;; vcursor-key-bindings to t before loading, or by customize, will
51 ;; what happens. (Find a scratch buffer before using C-S-tab: that 63 ;; define various keys with the prefix C-S. You'll have to read
52 ;; toggles copying.) 64 ;; further if you don't want this. Then I suggest you simply load it
65 ;; and play around with holding down Ctrl and Shift and pressing up,
66 ;; down, left, right, tab, return, and see what happens. (Find a
67 ;; scratch buffer before using C-S-tab: that toggles copying.)
53 ;; 68 ;;
54 ;; Most of the functions described in this documentation are in 69 ;; Most of the functions described in this documentation are in
55 ;; parentheses so that if you have the package loaded you can type C-h 70 ;; parentheses so that if you have the package loaded you can type C-h
56 ;; f on top of them for help. 71 ;; f on top of them for help.
57 ;; 72 ;;
155 ;; started. Note that once you are in isearch all the keys are normal 170 ;; started. Note that once you are in isearch all the keys are normal
156 ;; --- use C-s, not C-S-f8, to search for the next occurrence. 171 ;; --- use C-s, not C-S-f8, to search for the next occurrence.
157 ;; 172 ;;
158 ;; If you set the variable vcursor-auto-disable, then any command 173 ;; If you set the variable vcursor-auto-disable, then any command
159 ;; which does not involve moving or copying from the virtual cursor 174 ;; which does not involve moving or copying from the virtual cursor
160 ;; causes the virtual cursor to be disabled. If you don't intend to 175 ;; causes the virtual cursor to be disabled. If you set it to non-nil
161 ;; use this, you can comment out the `add-hook' line at the bottom of 176 ;; but not t, then the vcursor itself will remain active, but copying
162 ;; this file. (This feature partially emulates the way the "copy" key 177 ;; will be turned off, so that the next time the vcursor is moved no
163 ;; on the BBC micro worked; actually, the copy cursor was homed when 178 ;; text is copied over. Experience shows that this setting is
164 ;; you hit return. This was in keeping with the line-by-line way of 179 ;; particularly useful. If you don't intend to use this, you can
165 ;; entering BASIC, but is less appropriate here.) 180 ;; comment out the `add-hook' line at the bottom of this file. (This
181 ;; feature partially emulates the way the "copy" key on the BBC micro
182 ;; worked; actually, the copy cursor was homed when you hit return.
183 ;; This was in keeping with the line-by-line way of entering BASIC,
184 ;; but is less appropriate here.)
166 ;; 185 ;;
167 ;; vcursor-compare-windows is now a reliable adaption of 186 ;; vcursor-compare-windows is now a reliable adaption of
168 ;; compare-windows, which compares between point in the current buffer 187 ;; compare-windows, which compares between point in the current buffer
169 ;; and the vcursor location in the other one. It is an error if 188 ;; and the vcursor location in the other one. It is an error if
170 ;; vcursor is not set, however it will be brought up in another window 189 ;; vcursor is not set, however it will be brought up in another window
305 (defgroup vcursor nil 324 (defgroup vcursor nil
306 "Manipulate an alternative (\"virtual\") cursor." 325 "Manipulate an alternative (\"virtual\") cursor."
307 :prefix "vcursor-" 326 :prefix "vcursor-"
308 :group 'display) 327 :group 'display)
309 328
310 (or (memq 'vcursor (face-list)) 329 (defface vcursor
311 (progn 330 '((((class color)) (:foreground "blue" :background "cyan" :underline t))
312 (copy-face 'modeline 'vcursor) 331 (t (:inverse-video t :underline t)))
313 (if (or (fboundp 'oemacs-version) 332 "Face for the virtual cursor."
314 (and (eq window-system 'x) (x-display-color-p))) 333 :group 'vcursor)
315 (progn
316 (set-face-foreground 'vcursor "blue")
317 (set-face-background 'vcursor "cyan")))
318 (set-face-underline-p 'vcursor t)))
319 334
320 (defcustom vcursor-auto-disable nil 335 (defcustom vcursor-auto-disable nil
321 "*If non-nil, disable the virtual cursor after use. 336 "*If non-nil, disable the virtual cursor after use.
322 Any non-vcursor command will force `vcursor-disable' to be called." 337 Any non-vcursor command will force `vcursor-disable' to be called.
323 :type 'boolean 338 If non-nil but not t, just make sure copying is toggled off, but don't
339 disable the vcursor."
340 :type '(choice (const t) (const nil) (const copy))
324 :group 'vcursor) 341 :group 'vcursor)
325 342
326 (defcustom vcursor-key-bindings t 343 ;; Needed for defcustom, must be up here
327 "*How to bind keys when vcursor is loaded. 344 (if (not (string-match "XEmacs" emacs-version))
328 If t (the default), guess; if xterm, use bindings suitable for an 345 (defun vcursor-cs-binding (base &optional meta)
329 X terminal; if oemacs, use bindings which work on a PC with Oemacs. 346 (read (concat "[" (if meta "M-" "") "C-S-" base "]")))
330 If nil, don't define any key bindings." 347 (require 'overlay)
331 :type '(choice (const t) (const xterm) (const oemacs) (const nil)) 348 (defun vcursor-cs-binding (base &optional meta)
332 :group 'vcursor) 349 (read (concat "[(" (if meta "meta " "") "control shift "
333 350 base ")]")))
334 (defcustom vcursor-interpret-input nil 351 )
335 "*If non-nil, input from the vcursor is treated as interactive input. 352
336 This will cause text insertion to be much slower. Note that no special 353 (defun vcursor-bind-keys (var value)
337 interpretation of strings is done: \"\C-x\" is a string of four 354 "Alter the value of the variable VAR to VALUE, binding keys as required.
338 characters. The default is simply to copy strings." 355 VAR is usually vcursor-key-bindings. Normally this function is called
339 :type 'boolean 356 on loading vcursor and from the customize package."
340 :group 'vcursor 357 (set var value)
341 :version "20.3") 358 (cond
342 359 ((not value));; don't set any key bindings
343 (defcustom vcursor-string "**>" 360 ((or (eq value 'oemacs)
344 "String used to show the vcursor position on dumb terminals." 361 (and (eq value t) (fboundp 'oemacs-version)))
345 :type 'string 362 (global-set-key [C-f1] 'vcursor-toggle-copy)
346 :group 'vcursor 363 (global-set-key [C-f2] 'vcursor-copy)
347 :version "20.3") 364 (global-set-key [C-f3] 'vcursor-copy-word)
348 365 (global-set-key [C-f4] 'vcursor-copy-line)
349 (defvar vcursor-overlay nil 366
350 "Overlay for the virtual cursor. 367 (global-set-key [S-f1] 'vcursor-disable)
351 It is nil if that is not enabled.") 368 (global-set-key [S-f2] 'vcursor-other-window)
352 369 (global-set-key [S-f3] 'vcursor-goto)
353 (defvar vcursor-window nil 370 (global-set-key [S-f4] 'vcursor-swap-point)
354 "Last window to have displayed the virtual cursor. 371
355 See the function `vcursor-find-window' for how this is used.") 372 (global-set-key [C-f5] 'vcursor-backward-char)
356 373 (global-set-key [C-f6] 'vcursor-previous-line)
357 (defvar vcursor-last-command nil 374 (global-set-key [C-f7] 'vcursor-next-line)
358 "Non-nil if last command was a vcursor command. 375 (global-set-key [C-f8] 'vcursor-forward-char)
359 The commands `vcursor-copy', `vcursor-relative-move' and the ones for 376
360 scrolling set this. It is used by the `vcursor-auto-disable' code.") 377 (global-set-key [M-f5] 'vcursor-beginning-of-line)
361 ;; could do some memq-ing with last-command instead, but this will 378 (global-set-key [M-f6] 'vcursor-backward-word)
362 ;; automatically handle any new commands using the primitives. 379 (global-set-key [M-f6] 'vcursor-forward-word)
363 380 (global-set-key [M-f8] 'vcursor-end-of-line)
364 (defcustom vcursor-copy-flag nil 381
365 "*Non-nil means moving vcursor should copy characters moved over to point." 382 (global-set-key [S-f5] 'vcursor-beginning-of-buffer)
366 :type 'boolean 383 (global-set-key [S-f6] 'vcursor-scroll-down)
367 :group 'vcursor) 384 (global-set-key [S-f7] 'vcursor-scroll-up)
368 385 (global-set-key [S-f8] 'vcursor-end-of-buffer)
369 (defvar vcursor-temp-goal-column nil 386
370 "Keeps track of temporary goal columns for the virtual cursor.") 387 (global-set-key [C-f9] 'vcursor-isearch-forward)
371 388
372 (defvar vcursor-use-vcursor-map nil 389 (global-set-key [S-f9] 'vcursor-execute-key)
373 "Non-nil if the vcursor map is mapped directly onto the main keymap. 390 (global-set-key [S-f10] 'vcursor-execute-command)
374 See vcursor-toggle-vcursor-map.")
375 (make-variable-buffer-local 'vcursor-use-vcursor-map)
376
377 (defvar vcursor-map nil "Keymap for vcursor command.")
378 (define-prefix-command 'vcursor-map)
379
380 (define-key vcursor-map "t" 'vcursor-toggle-vcursor-map)
381
382 (define-key vcursor-map "\C-p" 'vcursor-previous-line)
383 (define-key vcursor-map "\C-n" 'vcursor-next-line)
384 (define-key vcursor-map "\C-b" 'vcursor-backward-char)
385 (define-key vcursor-map "\C-f" 'vcursor-forward-char)
386
387 (define-key vcursor-map "\r" 'vcursor-disable)
388 (define-key vcursor-map " " 'vcursor-copy)
389 (define-key vcursor-map "\C-y" 'vcursor-copy-word)
390 (define-key vcursor-map "\C-i" 'vcursor-toggle-copy)
391 (define-key vcursor-map "<" 'vcursor-beginning-of-buffer)
392 (define-key vcursor-map ">" 'vcursor-end-of-buffer)
393 (define-key vcursor-map "\M-v" 'vcursor-scroll-down)
394 (define-key vcursor-map "\C-v" 'vcursor-scroll-up)
395 (define-key vcursor-map "o" 'vcursor-other-window)
396 (define-key vcursor-map "g" 'vcursor-goto)
397 (define-key vcursor-map "x" 'vcursor-swap-point)
398 (define-key vcursor-map "\C-s" 'vcursor-isearch-forward)
399 (define-key vcursor-map "\C-r" 'vcursor-isearch-backward)
400 (define-key vcursor-map "\C-a" 'vcursor-beginning-of-line)
401 (define-key vcursor-map "\C-e" 'vcursor-end-of-line)
402 (define-key vcursor-map "\M-w" 'vcursor-forward-word)
403 (define-key vcursor-map "\M-b" 'vcursor-backward-word)
404 (define-key vcursor-map "\M-l" 'vcursor-copy-line)
405 (define-key vcursor-map "c" 'vcursor-compare-windows)
406 (define-key vcursor-map "k" 'vcursor-execute-key)
407 (define-key vcursor-map "\M-x" 'vcursor-execute-command)
408
409 (cond
410 ((not vcursor-key-bindings)) ;; don't set any key bindings
411 ((or (eq vcursor-key-bindings 'oemacs)
412 (and (eq vcursor-key-bindings t) (fboundp 'oemacs-version)))
413 (global-set-key [C-f1] 'vcursor-toggle-copy)
414 (global-set-key [C-f2] 'vcursor-copy)
415 (global-set-key [C-f3] 'vcursor-copy-word)
416 (global-set-key [C-f4] 'vcursor-copy-line)
417
418 (global-set-key [S-f1] 'vcursor-disable)
419 (global-set-key [S-f2] 'vcursor-other-window)
420 (global-set-key [S-f3] 'vcursor-goto)
421 (global-set-key [S-f4] 'vcursor-swap-point)
422
423 (global-set-key [C-f5] 'vcursor-backward-char)
424 (global-set-key [C-f6] 'vcursor-previous-line)
425 (global-set-key [C-f7] 'vcursor-next-line)
426 (global-set-key [C-f8] 'vcursor-forward-char)
427
428 (global-set-key [M-f5] 'vcursor-beginning-of-line)
429 (global-set-key [M-f6] 'vcursor-backward-word)
430 (global-set-key [M-f6] 'vcursor-forward-word)
431 (global-set-key [M-f8] 'vcursor-end-of-line)
432
433 (global-set-key [S-f5] 'vcursor-beginning-of-buffer)
434 (global-set-key [S-f6] 'vcursor-scroll-down)
435 (global-set-key [S-f7] 'vcursor-scroll-up)
436 (global-set-key [S-f8] 'vcursor-end-of-buffer)
437
438 (global-set-key [C-f9] 'vcursor-isearch-forward)
439
440 (global-set-key [S-f9] 'vcursor-execute-key)
441 (global-set-key [S-f10] 'vcursor-execute-command)
442 391
443 ;;; Partial dictionary of Oemacs key sequences for you to roll your own, 392 ;;; Partial dictionary of Oemacs key sequences for you to roll your own,
444 ;;; e.g C-S-up: (global-set-key "\M-[\C-f\M-\C-m" 'vcursor-previous-line) 393 ;;; e.g C-S-up: (global-set-key "\M-[\C-f\M-\C-m" 'vcursor-previous-line)
445 ;;; Sequence: Sends: 394 ;;; Sequence: Sends:
446 ;;; "\M-[\C-f\M-\C-m" C-S-up 395 ;;; "\M-[\C-f\M-\C-m" C-S-up
464 ;;; "\M-[\C-fc" C-S-f6 413 ;;; "\M-[\C-fc" C-S-f6
465 ;;; "\M-[\C-fd" C-S-f7 414 ;;; "\M-[\C-fd" C-S-f7
466 ;;; "\M-[\C-fe" C-S-f8 415 ;;; "\M-[\C-fe" C-S-f8
467 ;;; "\M-[\C-ff" C-S-f9 416 ;;; "\M-[\C-ff" C-S-f9
468 ;;; "\M-[\C-fg" C-S-f10 417 ;;; "\M-[\C-fg" C-S-f10
469 ) 418 )
470 (t 419 (t
471 (global-set-key [C-S-up] 'vcursor-previous-line) 420 (global-set-key (vcursor-cs-binding "up") 'vcursor-previous-line)
472 (global-set-key [C-S-down] 'vcursor-next-line) 421 (global-set-key (vcursor-cs-binding "down") 'vcursor-next-line)
473 (global-set-key [C-S-left] 'vcursor-backward-char) 422 (global-set-key (vcursor-cs-binding "left") 'vcursor-backward-char)
474 (global-set-key [C-S-right] 'vcursor-forward-char) 423 (global-set-key (vcursor-cs-binding "right") 'vcursor-forward-char)
475 424
476 (global-set-key [C-S-return] 'vcursor-disable) 425 (global-set-key (vcursor-cs-binding "return") 'vcursor-disable)
477 (global-set-key [C-S-insert] 'vcursor-copy) 426 (global-set-key (vcursor-cs-binding "insert") 'vcursor-copy)
478 (global-set-key [C-S-delete] 'vcursor-copy-word) 427 (global-set-key (vcursor-cs-binding "delete") 'vcursor-copy-word)
479 (global-set-key [C-S-remove] 'vcursor-copy-word) 428 (global-set-key (vcursor-cs-binding "remove") 'vcursor-copy-word)
480 (global-set-key [C-S-tab] 'vcursor-toggle-copy) 429 (global-set-key (vcursor-cs-binding "tab") 'vcursor-toggle-copy)
481 (global-set-key [C-S-home] 'vcursor-beginning-of-buffer) 430 (global-set-key (vcursor-cs-binding "backtab") 'vcursor-toggle-copy)
482 (global-set-key [M-C-S-up] 'vcursor-beginning-of-buffer) 431 (global-set-key (vcursor-cs-binding "home") 'vcursor-beginning-of-buffer)
483 (global-set-key [C-S-end] 'vcursor-end-of-buffer) 432 (global-set-key (vcursor-cs-binding "up" t) 'vcursor-beginning-of-buffer)
484 (global-set-key [M-C-S-down] 'vcursor-end-of-buffer) 433 (global-set-key (vcursor-cs-binding "end") 'vcursor-end-of-buffer)
485 (global-set-key [C-S-prior] 'vcursor-scroll-down) 434 (global-set-key (vcursor-cs-binding "down" t) 'vcursor-end-of-buffer)
486 (global-set-key [C-S-next] 'vcursor-scroll-up) 435 (global-set-key (vcursor-cs-binding "prior") 'vcursor-scroll-down)
436 (global-set-key (vcursor-cs-binding "next") 'vcursor-scroll-up)
487 437
488 (global-set-key [C-S-f6] 'vcursor-other-window) 438 (global-set-key (vcursor-cs-binding "f6") 'vcursor-other-window)
489 (global-set-key [C-S-f7] 'vcursor-goto) 439 (global-set-key (vcursor-cs-binding "f7") 'vcursor-goto)
490 440
491 (global-set-key [C-S-select] 'vcursor-swap-point) ; DEC keyboards 441 (global-set-key (vcursor-cs-binding "select")
492 (global-set-key [M-C-S-tab] 'vcursor-swap-point) 442 'vcursor-swap-point) ; DEC keyboards
493 443 (global-set-key (vcursor-cs-binding "tab" t) 'vcursor-swap-point)
494 (global-set-key [C-S-find] 'vcursor-isearch-forward) ; DEC keyboards 444
495 (global-set-key [C-S-f8] 'vcursor-isearch-forward) 445 (global-set-key (vcursor-cs-binding "find")
496 446 'vcursor-isearch-forward) ; DEC keyboards
497 (global-set-key [M-C-S-left] 'vcursor-beginning-of-line) 447 (global-set-key (vcursor-cs-binding "f8") 'vcursor-isearch-forward)
498 (global-set-key [M-C-S-right] 'vcursor-end-of-line) 448
499 449 (global-set-key (vcursor-cs-binding "left" t) 'vcursor-beginning-of-line)
500 (global-set-key [M-C-S-prior] 'vcursor-backward-word) 450 (global-set-key (vcursor-cs-binding "right" t) 'vcursor-end-of-line)
501 (global-set-key [M-C-S-next] 'vcursor-forward-word) 451
502 452 (global-set-key (vcursor-cs-binding "prior" t) 'vcursor-backward-word)
503 (global-set-key [M-C-S-return] 'vcursor-copy-line) 453 (global-set-key (vcursor-cs-binding "next" t) 'vcursor-forward-word)
504 454
505 (global-set-key [C-S-f9] 'vcursor-execute-key) 455 (global-set-key (vcursor-cs-binding "return" t) 'vcursor-copy-line)
506 (global-set-key [C-S-f10] 'vcursor-execute-command) 456
507 )) 457 (global-set-key (vcursor-cs-binding "f9") 'vcursor-execute-key)
458 (global-set-key (vcursor-cs-binding "f10") 'vcursor-execute-command)
459 )))
460
461 (defcustom vcursor-key-bindings nil
462 "*How to bind keys when vcursor is loaded.
463 If t, guess; if xterm, use bindings suitable for an X terminal; if
464 oemacs, use bindings which work on a PC with Oemacs. If nil, don't
465 define any key bindings.
466
467 Default is nil."
468 :type '(choice (const t) (const nil) (const xterm) (const oemacs))
469 :group 'vcursor
470 :set 'vcursor-bind-keys
471 :version "20.3")
472
473 (defcustom vcursor-interpret-input nil
474 "*If non-nil, input from the vcursor is treated as interactive input.
475 This will cause text insertion to be much slower. Note that no special
476 interpretation of strings is done: \"\C-x\" is a string of four
477 characters. The default is simply to copy strings."
478 :type 'boolean
479 :group 'vcursor
480 :version "20.3")
481
482 (defcustom vcursor-string "**>"
483 "String used to show the vcursor position on dumb terminals."
484 :type 'string
485 :group 'vcursor
486 :version "20.3")
487
488 (defvar vcursor-overlay nil
489 "Overlay for the virtual cursor.
490 It is nil if that is not enabled.")
491
492 (defvar vcursor-window nil
493 "Last window to have displayed the virtual cursor.
494 See the function `vcursor-find-window' for how this is used.")
495
496 (defvar vcursor-last-command nil
497 "Non-nil if last command was a vcursor command.
498 The commands `vcursor-copy', `vcursor-relative-move' and the ones for
499 scrolling set this. It is used by the `vcursor-auto-disable' code.")
500 ;; could do some memq-ing with last-command instead, but this will
501 ;; automatically handle any new commands using the primitives.
502
503 (defcustom vcursor-copy-flag nil
504 "*Non-nil means moving vcursor should copy characters moved over to point."
505 :type 'boolean
506 :group 'vcursor)
507
508 (defvar vcursor-temp-goal-column nil
509 "Keeps track of temporary goal columns for the virtual cursor.")
510
511 (defvar vcursor-use-vcursor-map nil
512 "Non-nil if the vcursor map is mapped directly onto the main keymap.
513 See vcursor-toggle-vcursor-map.")
514 (make-variable-buffer-local 'vcursor-use-vcursor-map)
515
516 (defvar vcursor-map nil "Keymap for vcursor command.")
517 (define-prefix-command 'vcursor-map)
518
519 (define-key vcursor-map "t" 'vcursor-toggle-vcursor-map)
520
521 (define-key vcursor-map "\C-p" 'vcursor-previous-line)
522 (define-key vcursor-map "\C-n" 'vcursor-next-line)
523 (define-key vcursor-map "\C-b" 'vcursor-backward-char)
524 (define-key vcursor-map "\C-f" 'vcursor-forward-char)
525
526 (define-key vcursor-map "\r" 'vcursor-disable)
527 (define-key vcursor-map " " 'vcursor-copy)
528 (define-key vcursor-map "\C-y" 'vcursor-copy-word)
529 (define-key vcursor-map "\C-i" 'vcursor-toggle-copy)
530 (define-key vcursor-map "<" 'vcursor-beginning-of-buffer)
531 (define-key vcursor-map ">" 'vcursor-end-of-buffer)
532 (define-key vcursor-map "\M-v" 'vcursor-scroll-down)
533 (define-key vcursor-map "\C-v" 'vcursor-scroll-up)
534 (define-key vcursor-map "o" 'vcursor-other-window)
535 (define-key vcursor-map "g" 'vcursor-goto)
536 (define-key vcursor-map "x" 'vcursor-swap-point)
537 (define-key vcursor-map "\C-s" 'vcursor-isearch-forward)
538 (define-key vcursor-map "\C-r" 'vcursor-isearch-backward)
539 (define-key vcursor-map "\C-a" 'vcursor-beginning-of-line)
540 (define-key vcursor-map "\C-e" 'vcursor-end-of-line)
541 (define-key vcursor-map "\M-w" 'vcursor-forward-word)
542 (define-key vcursor-map "\M-b" 'vcursor-backward-word)
543 (define-key vcursor-map "\M-l" 'vcursor-copy-line)
544 (define-key vcursor-map "c" 'vcursor-compare-windows)
545 (define-key vcursor-map "k" 'vcursor-execute-key)
546 (define-key vcursor-map "\M-x" 'vcursor-execute-command)
547
548 ;; If vcursor-key-bindings is already set on loading, bind the keys now.
549 ;; This hybrid way of doing it retains compatibility while allowing
550 ;; customize to work smoothly.
551 (if vcursor-key-bindings
552 (vcursor-bind-keys 'vcursor-key-bindings vcursor-key-bindings))
508 553
509 (defun vcursor-locate () 554 (defun vcursor-locate ()
510 "Go to the starting point of the virtual cursor. 555 "Go to the starting point of the virtual cursor.
511 If that's disabled, don't go anywhere but don't complain." 556 If that's disabled, don't go anywhere but don't complain."
512 ;; This is where we go off-mass-shell. Assume there is a 557 ;; This is where we go off-mass-shell. Assume there is a
513 ;; save-excursion to get us back to the pole, er, point. 558 ;; save-excursion to get us back to the pole, er, point.
514 559
515 (and (overlayp vcursor-overlay) 560 (and (overlayp vcursor-overlay)
516 (overlay-buffer vcursor-overlay) 561 (overlay-buffer vcursor-overlay)
517 (set-buffer (overlay-buffer vcursor-overlay)) 562 (set-buffer (overlay-buffer vcursor-overlay))
563 (overlay-start vcursor-overlay) ; needed for XEmacs
518 (goto-char (overlay-start vcursor-overlay))) 564 (goto-char (overlay-start vcursor-overlay)))
519 ) 565 )
520 566
521 (defun vcursor-find-window (&optional not-this new-win this-frame) 567 (defun vcursor-find-window (&optional not-this new-win this-frame)
522 "Return a suitable window for displaying the virtual cursor. 568 "Return a suitable window for displaying the virtual cursor.
1103 (or noredisp (redraw-display))))) 1149 (or noredisp (redraw-display)))))
1104 ) 1150 )
1105 1151
1106 (defun vcursor-post-command () 1152 (defun vcursor-post-command ()
1107 (and vcursor-auto-disable (not vcursor-last-command) 1153 (and vcursor-auto-disable (not vcursor-last-command)
1108 vcursor-overlay (vcursor-disable)) 1154 vcursor-overlay
1155 (if (eq vcursor-auto-disable t)
1156 (vcursor-disable)
1157 (vcursor-toggle-copy -1 t)))
1109 (setq vcursor-last-command nil) 1158 (setq vcursor-last-command nil)
1110 ) 1159 )
1111 1160
1112 (add-hook 'post-command-hook 'vcursor-post-command) 1161 (add-hook 'post-command-hook 'vcursor-post-command)
1113 1162