123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 |
- (eval-when-compile (require 'compare-w))
- (defgroup vcursor nil
- "Manipulate an alternative (\"virtual\") cursor."
- :prefix "vcursor-"
- :group 'convenience)
- (defface vcursor
- '((((class color)) (:foreground "blue" :background "cyan" :underline t))
- (t (:inverse-video t :underline t)))
- "Face for the virtual cursor."
- :group 'vcursor)
- (defcustom vcursor-auto-disable nil
- "If non-nil, disable the virtual cursor after use.
- Any non-vcursor command will force `vcursor-disable' to be called.
- If non-nil but not t, just make sure copying is toggled off, but don't
- disable the vcursor."
- :type '(choice (const t) (const nil) (const copy))
- :group 'vcursor)
- (defcustom vcursor-modifiers (list 'control 'shift)
- "A list of modifiers that are used to define vcursor key bindings."
- :type '(repeat symbol)
- :group 'vcursor)
- (defun vcursor-cs-binding (base &optional meta)
- (vector (let ((key (append vcursor-modifiers (list (intern base)))))
- (if meta
- (cons 'meta key)
- key))))
- (defun vcursor-bind-keys (var value)
- "Alter the value of the variable VAR to VALUE, binding keys as required.
- VAR is usually `vcursor-key-bindings'. Normally this function is called
- on loading vcursor and from the customize package."
- (set var value)
- (cond
- ((not value))
- ((or (eq value 'oemacs)
- (and (eq value t) (fboundp 'oemacs-version)))
- (global-set-key [C-f1] 'vcursor-toggle-copy)
- (global-set-key [C-f2] 'vcursor-copy)
- (global-set-key [C-f3] 'vcursor-copy-word)
- (global-set-key [C-f4] 'vcursor-copy-line)
- (global-set-key [S-f1] 'vcursor-disable)
- (global-set-key [S-f2] 'vcursor-other-window)
- (global-set-key [S-f3] 'vcursor-goto)
- (global-set-key [S-f4] 'vcursor-swap-point)
- (global-set-key [C-f5] 'vcursor-backward-char)
- (global-set-key [C-f6] 'vcursor-previous-line)
- (global-set-key [C-f7] 'vcursor-next-line)
- (global-set-key [C-f8] 'vcursor-forward-char)
- (global-set-key [M-f5] 'vcursor-beginning-of-line)
- (global-set-key [M-f6] 'vcursor-backward-word)
- (global-set-key [M-f6] 'vcursor-forward-word)
- (global-set-key [M-f8] 'vcursor-end-of-line)
- (global-set-key [S-f5] 'vcursor-beginning-of-buffer)
- (global-set-key [S-f6] 'vcursor-scroll-down)
- (global-set-key [S-f7] 'vcursor-scroll-up)
- (global-set-key [S-f8] 'vcursor-end-of-buffer)
- (global-set-key [C-f9] 'vcursor-isearch-forward)
- (global-set-key [S-f9] 'vcursor-execute-key)
- (global-set-key [S-f10] 'vcursor-execute-command)
- )
- (t
- (global-set-key (vcursor-cs-binding "up") 'vcursor-previous-line)
- (global-set-key (vcursor-cs-binding "down") 'vcursor-next-line)
- (global-set-key (vcursor-cs-binding "left") 'vcursor-backward-char)
- (global-set-key (vcursor-cs-binding "right") 'vcursor-forward-char)
- (global-set-key (vcursor-cs-binding "return") 'vcursor-disable)
- (global-set-key (vcursor-cs-binding "insert") 'vcursor-copy)
- (global-set-key (vcursor-cs-binding "delete") 'vcursor-copy-word)
- (global-set-key (vcursor-cs-binding "remove") 'vcursor-copy-word)
- (global-set-key (vcursor-cs-binding "tab") 'vcursor-toggle-copy)
- (global-set-key (vcursor-cs-binding "backtab") 'vcursor-toggle-copy)
- (global-set-key (vcursor-cs-binding "home") 'vcursor-beginning-of-buffer)
- (global-set-key (vcursor-cs-binding "up" t) 'vcursor-beginning-of-buffer)
- (global-set-key (vcursor-cs-binding "end") 'vcursor-end-of-buffer)
- (global-set-key (vcursor-cs-binding "down" t) 'vcursor-end-of-buffer)
- (global-set-key (vcursor-cs-binding "prior") 'vcursor-scroll-down)
- (global-set-key (vcursor-cs-binding "next") 'vcursor-scroll-up)
- (global-set-key (vcursor-cs-binding "f6") 'vcursor-other-window)
- (global-set-key (vcursor-cs-binding "f7") 'vcursor-goto)
- (global-set-key (vcursor-cs-binding "select")
- 'vcursor-swap-point)
- (global-set-key (vcursor-cs-binding "tab" t) 'vcursor-swap-point)
- (global-set-key (vcursor-cs-binding "find")
- 'vcursor-isearch-forward)
- (global-set-key (vcursor-cs-binding "f8") 'vcursor-isearch-forward)
- (global-set-key (vcursor-cs-binding "left" t) 'vcursor-beginning-of-line)
- (global-set-key (vcursor-cs-binding "right" t) 'vcursor-end-of-line)
- (global-set-key (vcursor-cs-binding "prior" t) 'vcursor-backward-word)
- (global-set-key (vcursor-cs-binding "next" t) 'vcursor-forward-word)
- (global-set-key (vcursor-cs-binding "return" t) 'vcursor-copy-line)
- (global-set-key (vcursor-cs-binding "f9") 'vcursor-execute-key)
- (global-set-key (vcursor-cs-binding "f10") 'vcursor-execute-command)
- )))
- (defcustom vcursor-key-bindings nil
- "How to bind keys when vcursor is loaded.
- If t, guess; if `xterm', use bindings suitable for an X terminal; if
- `oemacs', use bindings which work on a PC with Oemacs. If nil, don't
- define any key bindings.
- Default is nil."
- :type '(choice (const t) (const nil) (const xterm) (const oemacs))
- :group 'vcursor
- :set 'vcursor-bind-keys
- :version "20.3")
- (defcustom vcursor-interpret-input nil
- "If non-nil, input from the vcursor is treated as interactive input.
- This will cause text insertion to be much slower. Note that no special
- interpretation of strings is done: \"\C-x\" is a string of four
- characters. The default is simply to copy strings."
- :type 'boolean
- :group 'vcursor
- :version "20.3")
- (defcustom vcursor-string "**>"
- "String used to show the vcursor position on dumb terminals."
- :type 'string
- :group 'vcursor
- :version "20.3")
- (defvar vcursor-overlay nil
- "Overlay for the virtual cursor.
- It is nil if that is not enabled.")
- (defvar vcursor-window nil
- "Last window to have displayed the virtual cursor.
- See the function `vcursor-find-window' for how this is used.")
- (defvar vcursor-last-command nil
- "Non-nil if last command was a vcursor command.
- The commands `vcursor-copy', `vcursor-relative-move' and the ones for
- scrolling set this. It is used by the `vcursor-auto-disable' code.")
- (defcustom vcursor-copy-flag nil
- "Non-nil means moving vcursor should copy characters moved over to point."
- :type 'boolean
- :group 'vcursor)
- (defvar vcursor-temp-goal-column nil
- "Keeps track of temporary goal columns for the virtual cursor.")
- (defvar vcursor-map
- (let ((map (make-sparse-keymap)))
- (define-key map "t" 'vcursor-use-vcursor-map)
- (define-key map "\C-p" 'vcursor-previous-line)
- (define-key map "\C-n" 'vcursor-next-line)
- (define-key map "\C-b" 'vcursor-backward-char)
- (define-key map "\C-f" 'vcursor-forward-char)
- (define-key map "\r" 'vcursor-disable)
- (define-key map " " 'vcursor-copy)
- (define-key map "\C-y" 'vcursor-copy-word)
- (define-key map "\C-i" 'vcursor-toggle-copy)
- (define-key map "<" 'vcursor-beginning-of-buffer)
- (define-key map ">" 'vcursor-end-of-buffer)
- (define-key map "\M-v" 'vcursor-scroll-down)
- (define-key map "\C-v" 'vcursor-scroll-up)
- (define-key map "o" 'vcursor-other-window)
- (define-key map "g" 'vcursor-goto)
- (define-key map "x" 'vcursor-swap-point)
- (define-key map "\C-s" 'vcursor-isearch-forward)
- (define-key map "\C-r" 'vcursor-isearch-backward)
- (define-key map "\C-a" 'vcursor-beginning-of-line)
- (define-key map "\C-e" 'vcursor-end-of-line)
- (define-key map "\M-w" 'vcursor-forward-word)
- (define-key map "\M-b" 'vcursor-backward-word)
- (define-key map "\M-l" 'vcursor-copy-line)
- (define-key map "c" 'vcursor-compare-windows)
- (define-key map "k" 'vcursor-execute-key)
- (define-key map "\M-x" 'vcursor-execute-command)
- map)
- "Keymap for vcursor command.")
- (fset 'vcursor-map vcursor-map)
- (if vcursor-key-bindings
- (vcursor-bind-keys 'vcursor-key-bindings vcursor-key-bindings))
- (defun vcursor-locate ()
- "Go to the starting point of the virtual cursor.
- If that's disabled, don't go anywhere but don't complain."
-
-
- (and (overlayp vcursor-overlay)
- (overlay-buffer vcursor-overlay)
- (set-buffer (overlay-buffer vcursor-overlay))
- (goto-char (overlay-start vcursor-overlay)))
- )
- (defun vcursor-find-window (&optional not-this new-win this-frame)
- "Return a suitable window for displaying the virtual cursor.
- This is the first window in cyclic order where the vcursor is visible.
- With optional NOT-THIS non-nil never return the current window.
- With NEW-WIN non-nil, display the virtual cursor buffer in another
- window if the virtual cursor is not currently visible \(note, however,
- that this function never changes `window-point'\).
- With THIS-FRAME non-nil, don't search other frames for a new window
- \(though if the vcursor is already off-frame then its current window is
- always considered, and the value of `pop-up-frames' is always respected\).
- Returns nil if the virtual cursor is not visible anywhere suitable.
- Set `vcursor-window' to the returned value as a side effect."
-
-
-
-
-
-
-
-
- (let ((thiswin (selected-window)) winok winbuf)
- (save-excursion
- (vcursor-locate)
- (or (and (window-live-p vcursor-window)
- (eq (current-buffer) (window-buffer vcursor-window))
- (not (and not-this (eq thiswin vcursor-window))))
- (setq vcursor-window nil))
- (or (and vcursor-window
- (pos-visible-in-window-p (point) vcursor-window))
- (progn
- (walk-windows
- (function
- (lambda (win)
- (and (not winok)
- (eq (current-buffer) (window-buffer win))
- (not (and not-this (eq thiswin win)))
- (cond
- ((pos-visible-in-window-p (point) win) (setq winok win))
- ((eq thiswin win))
- ((not winbuf) (setq winbuf win))))))
- nil (not this-frame))
- (setq vcursor-window
- (cond
- (winok)
- ((and vcursor-window
- (not (eq thiswin vcursor-window))) vcursor-window)
- (winbuf)
- (new-win (display-buffer (current-buffer) t))
- (t nil)))))))
- vcursor-window
- )
- (defun vcursor-toggle-copy (&optional arg nomsg)
- "Toggle copying to point when the vcursor is moved.
- With a prefix ARG, turn on if non-negative, off if negative.
- Display a message unless optional NOMSG is non-nil."
- (interactive "P")
- (setq vcursor-copy-flag
- (cond ((not arg) (not vcursor-copy-flag))
- ((< (prefix-numeric-value arg) 0) nil)
- (t))
- vcursor-last-command t)
- (or nomsg (message "Copying from the vcursor is now %s."
- (if vcursor-copy-flag "on" "off")))
- )
- (defun vcursor-move (pt &optional leave-b leave-w)
- "Move the virtual cursor to the character to the right of PT.
- PT is an absolute location in the current buffer. With optional
- LEAVE-B, PT is in the same buffer the vcursor is currently in.
- If the new virtual cursor location would not be visible, display it in
- another window. With LEAVE-W, use the current `vcursor-window'."
-
- (save-excursion
- (and leave-b (vcursor-check t)
- (set-buffer (overlay-buffer vcursor-overlay)))
- (if (eq pt (point-max))
- (setq pt (1- pt)))
- (if (vcursor-check t)
- (move-overlay vcursor-overlay pt (+ pt 1) (current-buffer))
- (setq vcursor-overlay (make-overlay pt (+ pt 1)))
- (or window-system
- (display-color-p)
- (overlay-put vcursor-overlay 'before-string vcursor-string))
- (overlay-put vcursor-overlay 'face 'vcursor))
- (or leave-w (vcursor-find-window nil t))
-
- (or (pos-visible-in-window-p pt vcursor-window)
- (set-window-point vcursor-window pt)))
- )
- (defun vcursor-insert (text)
- "Insert TEXT, respecting `vcursor-interpret-input'."
- (if vcursor-interpret-input
- (setq unread-command-events
- (append (listify-key-sequence text) unread-command-events))
- (insert text))
- )
- (defun vcursor-relative-move (func &rest args)
- "Call FUNC with arbitrary ARGS ... to move the virtual cursor.
- This is called by most of the virtual-cursor motion commands."
- (let (text opoint)
- (save-excursion
- (vcursor-locate)
- (setq opoint (point))
- (apply func args)
- (and (eq opoint (point-max)) (eq opoint (point))
- (signal 'end-of-buffer nil))
- (vcursor-move (point))
- (if vcursor-copy-flag (setq text (buffer-substring opoint (point)))))
- (if text (vcursor-insert text)))
- (setq vcursor-last-command t)
- )
- (defun vcursor-goto (&optional arg)
- "Move the real cursor to the virtual cursor position.
- If the virtual cursor is (or was recently) visible in another window,
- switch to that first. Without a prefix ARG, disable the virtual
- cursor as well."
- (interactive "P")
- (and (vcursor-find-window) (select-window vcursor-window))
- (let ((buf (and vcursor-overlay (overlay-buffer vcursor-overlay))))
- (and buf (not (eq (current-buffer) buf)) (switch-to-buffer buf)))
- (vcursor-locate)
- (or arg (vcursor-disable))
- )
- (defun vcursor-swap-point ()
- "Swap the location of point and that of the virtual cursor.
- The virtual cursor window becomes the selected window and the old
- window becomes the virtual cursor window. If the virtual cursor would
- not be visible otherwise, display it in another window."
- (interactive)
- (let ((buf (current-buffer)) (here (point)) (win (selected-window)))
- (vcursor-goto)
- (with-current-buffer buf
- (setq vcursor-window win)
- (vcursor-move here)))
- )
- (defun vcursor-scroll-up (&optional n)
- "Scroll up the vcursor window ARG lines or near full screen if none.
- The vcursor will always appear in an unselected window."
- (interactive "P")
- (vcursor-window-funcall 'scroll-up n)
- )
- (defun vcursor-scroll-down (&optional n)
- "Scroll down the vcursor window ARG lines or near full screen if none.
- The vcursor will always appear in an unselected window."
- (interactive "P")
- (vcursor-window-funcall 'scroll-down n)
- )
- (defun vcursor-isearch-forward (&optional rep norecurs)
- "Perform forward incremental search in the virtual cursor window.
- The virtual cursor is moved to the resulting point; the ordinary
- cursor stays where it was."
- (interactive "P")
- (vcursor-window-funcall 'isearch-forward rep norecurs)
- )
- (defun vcursor-isearch-backward (&optional rep norecurs)
- "Perform backward incremental search in the virtual cursor window.
- The virtual cursor is moved to the resulting point; the ordinary
- cursor stays where it was."
- (interactive "P")
- (vcursor-window-funcall 'isearch-backward rep norecurs)
- )
- (defun vcursor-window-funcall (func &rest args)
- "Call FUNC with ARGS ... in a virtual cursor window.
- A window other than the currently-selected one will always be used.
- The virtual cursor is moved to the value of point when the function
- returns.
- If FUNC is a list, call the car of the list interactively, ignoring
- ARGS. In this case, a new window will not be created if the vcursor
- is visible in the current one."
- (vcursor-find-window (not (and (listp func) (vcursor-check t))) t)
- (save-excursion
- (let ((sw (selected-window)) text)
-
-
- (unwind-protect
- (let ((here (point)))
- (select-window vcursor-window)
- (vcursor-locate)
- (if (listp func)
- (call-interactively (car func))
- (apply func args))
- (setq vcursor-window (selected-window))
- (and vcursor-copy-flag
- (eq (current-buffer) (overlay-buffer vcursor-overlay))
- (setq text (buffer-substring here (point))))
-
-
- (vcursor-move (point) nil t))
- (select-window sw))
- (if text (vcursor-insert text))))
- (setq vcursor-last-command t)
- )
- (defun vcursor-get-char-count (func &rest args)
- "Apply FUNC to ARGS ... and return the number of characters moved.
- Point is temporarily set to the virtual cursor position before FUNC
- is called.
- This is called by most of the virtual-cursor copying commands to find
- out how much to copy."
- (vcursor-check)
- (with-current-buffer (overlay-buffer vcursor-overlay)
- (let ((start (goto-char (overlay-start vcursor-overlay))))
- (- (progn (apply func args) (point)) start)))
- )
- (defun vcursor-check (&optional arg)
- (cond
- ((and (overlayp vcursor-overlay) (overlay-start vcursor-overlay))
- t)
- (arg nil)
- (t (error "The virtual cursor is not active now")))
- )
- (define-minor-mode vcursor-use-vcursor-map
- "Toggle the state of the vcursor key map.
- With a prefix argument ARG, enable it if ARG is positive, and disable
- it otherwise. If called from Lisp, enable it if ARG is omitted or nil.
- When on, the keys defined in it are mapped directly on top of the main
- keymap, allowing you to move the vcursor with ordinary motion keys.
- An indication \"!VC\" appears in the mode list. The effect is
- local to the current buffer.
- Disabling the vcursor automatically turns this off."
- :keymap vcursor-map
- :lighter " !VC")
- (defun vcursor-disable (&optional arg)
- "Disable the virtual cursor.
- Next time you use it, it will start from point.
- With a positive prefix ARG, the first window in cyclic order
- displaying the virtual cursor (or which was recently displaying the
- virtual cursor) will be deleted unless it's the selected window.
- With a negative prefix argument, enable the virtual cursor: make it
- active at the same point as the real cursor.
- Copying mode is always turned off: the next use of the vcursor will
- not copy text until you turn it on again."
- (interactive "P")
- (if (overlayp vcursor-overlay)
- (progn
- (delete-overlay vcursor-overlay)
- (setq vcursor-overlay nil)))
- (cond
- ((not (vcursor-find-window t)))
- ((or (not arg) (< (prefix-numeric-value arg) 0)))
- ((delete-window vcursor-window)))
- (cond
- ((and arg (< (prefix-numeric-value arg) 0))
- (vcursor-move (point))
- (setq vcursor-window (selected-window)))
- (vcursor-use-vcursor-map (vcursor-use-vcursor-map 0)))
- (setq vcursor-copy-flag nil)
- )
- (defun vcursor-other-window (n &optional all-frames)
- "Activate the virtual cursor in another window.
- This is the next window cyclically after one currently showing the
- virtual cursor, or else after the current selected window. If there
- is no other window, the current window is split.
- Arguments N and optional ALL-FRAMES are the same as with `other-window'.
- ALL-FRAMES is also used to decide whether to split the window."
- (interactive "p")
- (if (if (fboundp 'oemacs-version)
- (one-window-p nil)
- (one-window-p nil all-frames))
- (display-buffer (current-buffer) t))
- (save-excursion
- (save-window-excursion
-
-
-
- (let ((win (vcursor-find-window nil nil (not all-frames))))
- (if win (select-window win))
-
- (other-window n all-frames)
- (vcursor-disable -1))))
- )
- (defun vcursor-compare-windows (&optional ignore-whitespace)
- "Compare text in current window with text in window with vcursor.
- Compares the text starting at point in the current window and at the
- vcursor position in the other window, moving over text in each one as
- far as they match.
- A prefix argument, if any, means ignore changes in whitespace.
- The variable `compare-windows-whitespace' controls how whitespace is skipped.
- If `compare-ignore-case' is non-nil, changes in case are also ignored."
- (interactive "P")
-
- (require 'compare-w)
- (let* (p1 p2 maxp1 maxp2 b1 b2 w2
- success
- (opoint1 (point))
- opoint2
- (skip-whitespace (if ignore-whitespace
- compare-windows-whitespace)))
- (setq p1 (point) b1 (current-buffer))
- (setq w2 (vcursor-find-window t t))
- (if (or (eq w2 (selected-window)) (not w2))
- (error "No other window with vcursor"))
- (save-excursion
- (vcursor-locate)
- (setq p2 (point) b2 (current-buffer)))
- (setq opoint2 p2)
- (setq maxp1 (point-max))
- (with-current-buffer b2
- (setq maxp2 (point-max)))
- (setq success t)
- (while success
- (setq success nil)
-
- (goto-char p1)
- (vcursor-move p2 t)
-
-
- (and skip-whitespace
- (save-excursion
- (let (p1a p2a result1 result2)
- (setq result1
- (if (stringp skip-whitespace)
- (compare-windows-skip-whitespace opoint1)
- (funcall skip-whitespace opoint1)))
- (setq p1a (point))
- (set-buffer b2)
- (goto-char p2)
- (setq result2
- (if (stringp skip-whitespace)
- (compare-windows-skip-whitespace opoint2)
- (funcall skip-whitespace opoint2)))
- (setq p2a (point))
- (if (or (stringp skip-whitespace)
- (and result1 result2 (eq result1 result2)))
- (setq p1 p1a
- p2 p2a)))))
-
-
- (let ((size 1000)
- success-1
- (case-fold-search compare-ignore-case))
- (while (> size 0)
- (setq success-1 t)
-
- (while success-1
- (setq size (min size (- maxp1 p1) (- maxp2 p2)))
- (setq success-1
- (and (> size 0)
- (= 0 (compare-buffer-substrings b2 p2 (+ size p2)
- b1 p1 (+ size p1)))))
- (if success-1
- (setq p1 (+ p1 size) p2 (+ p2 size)
- success t)))
-
- (setq size (/ size 2)))))
- (goto-char p1)
- (vcursor-move p2 t)
- (if (= (point) opoint1)
- (ding)))
- )
- (defun vcursor-next-line (arg)
- "Move the virtual cursor forward ARG lines."
-
-
- (interactive "p")
- (let (temporary-goal-column opoint text)
- (save-excursion
- (vcursor-locate)
- (setq temporary-goal-column
- (if (or (eq last-command 'vcursor-next-line)
- (eq last-command 'vcursor-previous-line))
- (progn
- (setq last-command 'next-line)
- vcursor-temp-goal-column)
- (if (and track-eol (eolp)
- (or (not (bolp)) (eq last-command 'end-of-line)))
- 9999
- (current-column)))
- opoint (point))
- (line-move arg)
- (and (eq opoint (point-max)) (eq opoint (point))
- (signal 'end-of-buffer nil))
- (if vcursor-copy-flag (setq text (buffer-substring opoint (point))))
- (vcursor-move (point))
- (setq vcursor-temp-goal-column temporary-goal-column
- vcursor-last-command t))
- (if text (vcursor-insert text)))
- )
- (defun vcursor-previous-line (arg)
- "Move the virtual cursor back ARG lines."
- (interactive "p")
- (vcursor-next-line (- arg))
- )
- (defun vcursor-forward-char (arg)
- "Move the virtual cursor forward ARG characters."
- (interactive "p")
- (vcursor-relative-move 'forward-char arg)
- )
- (defun vcursor-backward-char (arg)
- "Move the virtual cursor backward ARG characters."
- (interactive "p")
- (vcursor-relative-move 'backward-char arg)
- )
- (defun vcursor-forward-word (arg)
- "Move the virtual cursor forward ARG words."
- (interactive "p")
- (vcursor-relative-move 'forward-word arg)
- )
- (defun vcursor-backward-word (arg)
- "Move the virtual cursor backward ARG words."
- (interactive "p")
- (vcursor-relative-move 'backward-word arg)
- )
- (defun vcursor-beginning-of-line (arg)
- "Move the virtual cursor to beginning of its current line.
- ARG is as for `beginning-of-line'."
- (interactive "P")
- (vcursor-relative-move 'beginning-of-line
- (if arg (prefix-numeric-value arg)))
- )
- (defun vcursor-end-of-line (arg)
- "Move the virtual cursor to end of its current line.
- ARG is as for `end-of-line'."
- (interactive "P")
- (vcursor-relative-move 'end-of-line
- (if arg (prefix-numeric-value arg)))
- )
- (defun vcursor-beginning-of-buffer (&optional arg)
- "Move the virtual cursor to the beginning of its buffer.
- ARG is as for `beginning-of-buffer'."
- (interactive "P")
- (vcursor-relative-move
- (lambda (arg)
- (goto-char (if arg (/ (* arg (- (point-max) (point-min))) 10)
- (point-min))))
- (if arg (prefix-numeric-value arg)))
- )
- (defun vcursor-end-of-buffer (&optional arg)
- "Move the virtual cursor to the end of its buffer.
- ARG is as for `end-of-buffer'.
- Actually, the vcursor is moved to the second from last character or it
- would be invisible."
- (interactive "P")
- (vcursor-relative-move
- (lambda (arg)
- (goto-char (if arg (- (point-max)
- (/ (* arg (- (point-max) (point-min))) 10))
- (point-max))))
- (if arg (prefix-numeric-value arg)))
- )
- (defun vcursor-execute-command (cmd)
- "Execute COMMAND for the virtual cursor.
- COMMAND is called interactively. Not all commands (in fact, only a
- small subset) are useful."
- (interactive "CCommand: ")
- (vcursor-window-funcall (list cmd))
- )
- (defun vcursor-execute-key ()
- "Read a key sequence and execute the bound command for the virtual cursor.
- The key sequence is read at the vcursor location. The command found
- is called interactively, so prefix argument etc. are usable."
- (interactive)
- (let (cmd)
- (save-excursion
-
-
- (vcursor-find-window (not (vcursor-check t)) t)
- (save-window-excursion
- (select-window vcursor-window)
- (vcursor-locate)
- (setq cmd (key-binding (read-key-sequence "Key sequence: ")))))
- (vcursor-window-funcall (list cmd)))
- )
- (defun vcursor-copy (arg)
- "Copy ARG characters from the virtual cursor position to point."
- (interactive "p")
- (vcursor-check)
- (vcursor-insert
- (with-current-buffer (overlay-buffer vcursor-overlay)
- (let* ((ostart (overlay-start vcursor-overlay))
- (end (+ ostart arg)))
- (prog1
- (buffer-substring ostart end)
- (vcursor-move end)))))
- (setq vcursor-last-command t)
- )
- (defun vcursor-copy-word (arg)
- "Copy ARG words from the virtual cursor position to point."
- (interactive "p")
- (vcursor-copy (vcursor-get-char-count 'forward-word arg))
- )
- (defun vcursor-copy-line (arg)
- "Copy up to ARGth line after virtual cursor position.
- With no argument, copy to the end of the current line.
- Behavior with regard to newlines is similar (but not identical) to
- `kill-line'; the main difference is that whitespace at the end of the
- line is treated like ordinary characters."
- (interactive "P")
- (let* ((num (prefix-numeric-value arg))
- (count (vcursor-get-char-count 'end-of-line num)))
- (vcursor-copy (if (or (= count 0) arg) (1+ count) count)))
- )
- (define-obsolete-function-alias
- 'vcursor-toggle-vcursor-map 'vcursor-use-vcursor-map "23.1")
- (defun vcursor-post-command ()
- (and vcursor-auto-disable (not vcursor-last-command)
- vcursor-overlay
- (if (eq vcursor-auto-disable t)
- (vcursor-disable)
- (vcursor-toggle-copy -1 t)))
- (setq vcursor-last-command nil)
- )
- (add-hook 'post-command-hook 'vcursor-post-command)
- (provide 'vcursor)
|