Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise vi-mode's jumplist #1093

Merged
merged 14 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:lem-vi-mode/core
:lem-vi-mode/word
:lem-vi-mode/visual
:lem-vi-mode/jump-motions
:lem-vi-mode/jumplist
:lem-vi-mode/registers
:lem-vi-mode/text-objects
:lem-vi-mode/commands/utils)
Expand Down Expand Up @@ -632,7 +632,7 @@
(define-command vi-search-forward () ()
(setf *last-search-direction* :forward)
(add-hook *isearch-finish-hooks* 'vi-isearch-finish-hook)
(with-jump-motion
(with-jumplist
(lem/isearch::isearch-start "/"
(lambda (point string)
(alexandria:when-let (p (lem/isearch::search-forward-regexp
Expand All @@ -647,13 +647,13 @@
(define-command vi-search-backward () ()
(setf *last-search-direction* :backward)
(add-hook *isearch-finish-hooks* 'vi-isearch-finish-hook)
(with-jump-motion
(with-jumplist
(lem/isearch:isearch-backward-regexp "?")))

(defun vi-search-repeat-forward (n)
(when-let ((query (register #\/)))
(lem/isearch::change-previous-string query)
(with-jump-motion
(with-jumplist
(with-point ((p (current-point)))
(vi-forward-char (length lem/isearch::*isearch-string*))
(loop repeat n
Expand All @@ -667,7 +667,7 @@
(defun vi-search-repeat-backward (n)
(when-let ((query (register #\/)))
(lem/isearch::change-previous-string query)
(with-jump-motion
(with-jumplist
(dotimes (i n) (lem/isearch:isearch-prev)))))

(define-command vi-search-next (n) ("p")
Expand All @@ -681,7 +681,7 @@
(:backward (vi-search-repeat-forward n))))

(define-command vi-search-forward-symbol-at-point () ()
(with-jump-motion
(with-jumplist
(lem/isearch:isearch-forward-symbol-at-point)
(lem/isearch:isearch-finish)
(lem/isearch:isearch-next)))
Expand Down
20 changes: 11 additions & 9 deletions extensions/vi-mode/commands/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
:text-object-abort-range)
(:import-from :lem-vi-mode/states
:operator)
(:import-from :lem-vi-mode/jump-motions
:with-jump-motion)
(:import-from :lem-vi-mode/jumplist
:with-jumplist
:without-jumplist)
(:import-from :lem-vi-mode/visual
:visual-p
:visual-line-p
Expand Down Expand Up @@ -108,7 +109,7 @@
:default-n-arg ,default-n-arg))
,arg-list ,arg-descriptors
(with-point ((*vi-origin-point* (current-point)))
(,(if jump 'with-jump-motion 'progn)
(,(if jump 'with-jumplist 'progn)
,@body))))

(defun call-motion-command (command n)
Expand Down Expand Up @@ -213,12 +214,13 @@

(defun call-define-operator (fn &key keep-visual restore-point)
(with-point ((*vi-origin-point* (current-point)))
(unwind-protect (funcall fn)
(when restore-point
(move-point (current-point) *vi-origin-point*))
(unless keep-visual
(when (visual-p)
(vi-visual-end))))))
(without-jumplist
(unwind-protect (funcall fn)
(when restore-point
(move-point (current-point) *vi-origin-point*))
(unless keep-visual
(when (visual-p)
(vi-visual-end)))))))

(defun parse-arg-descriptors (arg-descriptors &key motion move-point)
`(values-list
Expand Down
24 changes: 19 additions & 5 deletions extensions/vi-mode/ex-command.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(defpackage :lem-vi-mode/ex-command
(:use :cl
:lem-vi-mode/ex-core)
(:import-from :lem-vi-mode/jump-motions
:with-jump-motion)
(:import-from :lem-vi-mode/jumplist
:with-jumplist
:window-jumplist
:current-jumplist
:copy-jumplist)
(:import-from :lem-vi-mode/options
:execute-set-command)
(:import-from :lem-vi-mode/utils
Expand All @@ -27,7 +30,8 @@

(define-ex-command "^e$" (range filename)
(declare (ignore range))
(lem:find-file (merge-pathnames (expand-filename-modifiers filename) (uiop:getcwd))))
(with-jumplist
(lem:find-file (merge-pathnames (expand-filename-modifiers filename) (uiop:getcwd)))))

(define-ex-command "^(w|write)$" (range filename)
(ex-write range filename t))
Expand Down Expand Up @@ -72,21 +76,30 @@
(define-ex-command "^(x|xit)!$" (range filename)
(ex-write-quit range filename t nil))

(defun copy-current-jumplist-to-next-window ()
(let* ((window-list
(lem:compute-window-list (lem:current-window)))
(new-window (lem:get-next-window (lem:current-window) window-list)))
(setf (window-jumplist new-window)
(copy-jumplist (current-jumplist)))))

(define-ex-command "^(sp|split)$" (range filename)
(declare (ignore range))
(lem:split-active-window-vertically)
(copy-current-jumplist-to-next-window)
(unless (string= filename "")
(lem:find-file (merge-pathnames (expand-filename-modifiers filename) (uiop:getcwd)))))

(define-ex-command "^(vs|vsplit)$" (range filename)
(declare (ignore range))
(lem:split-active-window-horizontally)
(copy-current-jumplist-to-next-window)
(lem:next-window)
(unless (string= filename "")
(lem:find-file (merge-pathnames (expand-filename-modifiers filename) (uiop:getcwd)))))

(define-ex-command "^(s|substitute)$" (range argument)
(with-jump-motion
(with-jumplist
(let (start end)
(case (length range)
((0)
Expand Down Expand Up @@ -149,7 +162,8 @@

(define-ex-command "^(b|buffer)$" (range buffer-name)
(declare (ignore range))
(lem:select-buffer buffer-name))
(with-jumplist
(lem:select-buffer buffer-name)))

(define-ex-command "^bd(?:elete)?$" (range buffer-name)
(declare (ignore range))
Expand Down
42 changes: 0 additions & 42 deletions extensions/vi-mode/jump-motions.lisp

This file was deleted.

Loading