TheLonelyStar <[email protected]> writes: > Hi, > > I use vimpulse. When I do C-o it jumps to the last mark in the current file. > Can i somehow make it use global marks?
Hi, let's have this discussion on the vim-emulation list, which I am hereby Cc:-ing (and please remove the help list from the Cc: header when replying; I don't think most people here are interested in this). I consider this to be a problem, too, and even started to implement it before some time, but as I almost never use it and nobody else seemed to ever mention this, it remained a stub, i.e. it sort-of works, but a bit funnily and not quite as in Vim (yet). Here is what I came up with (you can apply the diff provided you use the Git repository, not the single vimpulse.el file):
diff --git a/vimpulse-dependencies.el b/vimpulse-dependencies.el index 692e823..1e31753 100644 --- a/vimpulse-dependencies.el +++ b/vimpulse-dependencies.el @@ -215,16 +215,13 @@ (defvar vimpulse-core-movement-cmds "List of Viper \"core\" movement commands. These should be present in every mode, to avoid confusion.") -(viper-deflocalvar vimpulse-mark-list nil - "List of mark positions to jump to with `vimpulse-jump-forward'. - They are stored as markers, the current position first: - - (car vimpulse-mark-list) = current position (last popped) - (cdr vimpulse-mark-list) = future positions (previously popped) - (cadr vimpulse-mark-list) = next position (to jump to) +(defvar vimpulse-jump-list-max 100 + "Maximum number of jumps to store.") - In other words, a sort of \"reverse mark ring\": marks that are - popped off the mark ring, are collected here.") +(defvar vimpulse-jump-list (make-ring vimpulse-jump-list-max) + "List of mark positions to jump to with `vimpulse-jump-forward'. +\(The actual data structure used is a ring, not list.) +They are stored as markers, the current position first.") (viper-deflocalvar vimpulse-local-marks-alist nil "Association list of local marks. diff --git a/vimpulse-misc-keybindings.el b/vimpulse-misc-keybindings.el index 7832afd..e18fa7a 100644 --- a/vimpulse-misc-keybindings.el +++ b/vimpulse-misc-keybindings.el @@ -500,58 +500,69 @@ (defalias 'viper-autoindent 'vimpulse-autoindent) ;;; C-o, C-i -(defadvice set-mark (after vimpulse activate) - "Clear `vimpulse-mark-list'." - (mapc (lambda (marker) - (set-marker marker nil)) - vimpulse-mark-list) - (setq vimpulse-mark-list nil)) - -(defadvice push-mark (after vimpulse activate) - "Clear `vimpulse-mark-list'." - (mapc (lambda (marker) - (set-marker marker nil)) - vimpulse-mark-list) - (setq vimpulse-mark-list nil)) +;; TODO / % +(defvar vimpulse-jump-commands + '(vimpulse-jump-to-tag-at-point viper-backward-paragraph + viper-forward-paragraph viper-backward-sentence viper-forward-sentence + viper-brac-function viper-goto-line viper-goto-mark + viper-goto-mark-and-skip-white viper-search-next viper-search-Next + viper-window-bottom viper-window-middle viper-window-top) + "Commands that constitute a \"jump\".") + +(defun vimpulse-record-jump () + (ring-insert vimpulse-jump-list + (cons buffer-file-name (move-marker (make-marker) (point))))) + +(defmacro vimpulse-jump-advice (fun) + (let ((funcname (symbol-value fun))) + `(defadvice ,funcname (before vimpulse-record-jump activate) + (vimpulse-record-jump)))) + +(dolist (c vimpulse-jump-commands) + (vimpulse-jump-advice c)) + +(defvar vimpulse-jump-list-curpos nil) + +(defun vimpulse-jump-to (pos) + (let ((file (car pos)) + (marker (cdr pos))) + (if (equal buffer-file-name file) + (goto-char marker) + (if (null file) + (if (marker-buffer marker) + (progn (switch-to-buffer (marker-buffer marker)) + (goto-char marker)) + (message "Buffer does not exist, removing from jump list") + (ring-remove vimpulse-jump-list vimpulse-jump-list-curpos)) + (or (and (or (find-buffer-visiting file) + (y-or-n-p (format "Visit file %s again? " file))) + (find-file file) + (goto-char marker)) + (message "Kthx")))))) (defun vimpulse-jump-backward (arg) "Go to older position in jump list. - To go the other way, press \\[vimpulse-jump-forward]." +For the opposite direction, use \\[vimpulse-jump-forward]." (interactive "p") - (let ((current-pos (make-marker)) i) - (unless vimpulse-mark-list - (move-marker current-pos (point)) - (add-to-list 'vimpulse-mark-list current-pos)) - (dotimes (arg arg) - (setq current-pos (make-marker)) - ;; Skip past duplicate entries in the mark ring. - (setq i (length mark-ring)) - (while (progn (move-marker current-pos (point)) - (let (vimpulse-mark-list) - ;; Protect `vimpulse-mark-list'. - (set-mark-command 0)) - (setq i (1- i)) - (and (= (point) current-pos) (> i 0)))) - ;; Already there? - (move-marker current-pos (point)) - (unless (= (car vimpulse-mark-list) current-pos) - (setq vimpulse-mark-list - (cons current-pos vimpulse-mark-list)))))) + (if (memq last-command '(vimpulse-jump-backward vimpulse-jump-forward)) + (vimpulse-jump-to (ring-ref vimpulse-jump-list + (setq vimpulse-jump-list-curpos + (+ vimpulse-jump-list-curpos arg)))) + (vimpulse-record-jump) + (vimpulse-jump-to (ring-ref vimpulse-jump-list + (setq vimpulse-jump-list-curpos arg))))) (defun vimpulse-jump-forward (arg) "Go to newer position in jump list. - To go the other way, press \\[vimpulse-jump-backward]." +For the opposite direction, use \\[vimpulse-jump-backward]." (interactive "p") - (let (current-pos next-pos) - (dotimes (arg arg) - (setq current-pos (car vimpulse-mark-list) - next-pos (cadr vimpulse-mark-list)) - (when next-pos - ;; Protect `vimpulse-mark-list'. - (let (vimpulse-mark-list) - (push-mark current-pos t nil)) - (goto-char next-pos) - (setq vimpulse-mark-list (cdr vimpulse-mark-list)))))) + (if (memq last-command '(vimpulse-jump-backward vimpulse-jump-forward)) + (vimpulse-jump-to (ring-ref vimpulse-jump-list + (setq vimpulse-jump-list-curpos + (- vimpulse-jump-list-curpos arg)))) + (vimpulse-record-jump) + (vimpulse-jump-to (ring-ref vimpulse-jump-list + (setq vimpulse-jump-list-curpos (- arg)))))) (when vimpulse-want-C-i-like-Vim (define-key viper-vi-basic-map "\C-i" 'vimpulse-jump-forward))
Štěpán
_______________________________________________ implementations-list mailing list [email protected] https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list
