Skip to content

Make the placing of marks consistant for INSERT state. #675

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

Merged
merged 1 commit into from
Jul 16, 2025
Merged
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
4 changes: 2 additions & 2 deletions meow-beacon.el
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ Non-nil BACKWARD means backward direction."
(meow--cancel-selection)
(thread-first
(meow--make-selection '(select . transient) m (point))
(meow--select)))
(meow--select t)))
(meow--cancel-selection)))

(defun meow--beacon-apply-command (cmd)
@@ -117,7 +117,7 @@ Non-nil BACKWARD means backward direction."
(meow--make-selection
type (overlay-end ov) (overlay-start ov))
(meow--make-selection type (overlay-start ov) (overlay-end ov)))
(meow--select)))
(meow--select t)))

(call-interactively cmd))
(delete-overlay ov))))))))
99 changes: 58 additions & 41 deletions meow-command.el
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ The direction of selection is MARK -> POS."
(message "Mark set"))
nil)

(defun meow--select (selection &optional backward)
(defun meow--select (selection &optional activate backward)
"Mark the SELECTION."
(let* ((old-sel-type (meow--selection-type))
(sel-type (car selection))
@@ -84,7 +84,7 @@ The direction of selection is MARK -> POS."
(cond
((null old-sel-type)
(goto-char to-go)
(push-mark to-mark t t))
(push-mark to-mark t activate))
(t
(goto-char to-go)
(set-mark to-mark)))
@@ -492,8 +492,9 @@ With argument ARG, do this that many times."
(meow--direction-backward)
(meow--cancel-selection)
(meow--switch-state 'insert)
(setq-local meow--insert-pos (point))
(when meow-select-on-insert
(setq-local meow--insert-pos (point)))))
(setq-local meow--insert-activate-mark t))))

(defun meow-append ()
"Move to the end of selection, switch to INSERT state."
@@ -509,8 +510,9 @@ With argument ARG, do this that many times."
(meow--direction-forward)
(meow--cancel-selection))
(meow--switch-state 'insert)
(setq-local meow--insert-pos (point))
(when meow-select-on-append
(setq-local meow--insert-pos (point)))))
(setq-local meow--insert-activate-mark t))))

(defun meow-open-above ()
"Open a newline above and switch to INSERT state."
@@ -525,7 +527,10 @@ With argument ARG, do this that many times."
(newline))
;; (save-mark-and-excursion
;; (meow--insert "\n"))
(indent-according-to-mode)))
(indent-according-to-mode)
(setq-local meow--insert-pos (point))
(when meow-select-on-open
(setq-local meow--insert-activate-mark t))))

(defun meow-open-above-visual ()
"Open a newline above and switch to INSERT state."
@@ -538,7 +543,10 @@ With argument ARG, do this that many times."
(goto-char (meow--visual-line-beginning-position))
(save-mark-and-excursion
(newline))
(indent-according-to-mode)))
(indent-according-to-mode)
(setq-local meow--insert-pos (point))
(when meow-select-on-open
(setq-local meow--insert-activate-mark t))))

(defun meow-open-below ()
"Open a newline below and switch to INSERT state."
@@ -549,7 +557,10 @@ With argument ARG, do this that many times."
(meow--switch-state 'motion))
(meow--switch-state 'insert)
(goto-char (line-end-position))
(meow--execute-kbd-macro "RET")))
(meow--execute-kbd-macro "RET")
(setq-local meow--insert-pos (point))
(when meow-select-on-open
(setq-local meow--insert-activate-mark t))))

(defun meow-open-below-visual ()
"Open a newline below and switch to INSERT state."
@@ -560,7 +571,10 @@ With argument ARG, do this that many times."
(meow--switch-state 'motion))
(meow--switch-state 'insert)
(goto-char (meow--visual-line-end-position))
(meow--execute-kbd-macro "RET")))
(meow--execute-kbd-macro "RET")
(setq-local meow--insert-pos (point))
(when meow-select-on-open
(setq-local meow--insert-activate-mark t))))

(defun meow-change ()
"Kill current selection and switch to INSERT state.
@@ -572,26 +586,29 @@ This command supports `meow-selection-command-fallback'."
(meow--with-selection-fallback
(meow--delete-region (region-beginning) (region-end))
(meow--switch-state 'insert)
(setq-local meow--insert-pos (point))
(when meow-select-on-change
(setq-local meow--insert-pos (point))))))
(setq-local meow--insert-activate-mark t)))))

(defun meow-change-char ()
"Delete current char and switch to INSERT state."
(interactive)
(when (< (point) (point-max))
(meow--execute-kbd-macro meow--kbd-delete-char)
(meow--switch-state 'insert)
(setq-local meow--insert-pos (point))
(when meow-select-on-change
(setq-local meow--insert-pos (point)))))
(setq-local meow--insert-activate-mark t))))

(defun meow-change-save ()
(interactive)
(let ((select-enable-clipboard meow-use-clipboard))
(when (and (meow--allow-modify-p) (region-active-p))
(kill-region (region-beginning) (region-end))
(meow--switch-state 'insert)
(setq-local meow--insert-pos (point))
(when meow-select-on-change
(setq-local meow--insert-pos (point))))))
(setq-local meow--insert-activate-mark t)))))

(defun meow-replace ()
"Replace current selection with yank.
@@ -700,12 +717,12 @@ Will cancel all other selection, except char selection. "
(if (region-active-p)
(thread-first
(meow--make-selection '(expand . char) (mark) (point))
(meow--select))
(meow--select t))
(when meow-use-cursor-position-hack
(forward-char 1))
(thread-first
(meow--make-selection '(expand . char) (point) (point))
(meow--select)))
(meow--select t)))
(meow--execute-kbd-macro meow--kbd-backward-char))

(defun meow-right-expand ()
@@ -714,10 +731,10 @@ Will cancel all other selection, except char selection. "
(if (region-active-p)
(thread-first
(meow--make-selection '(expand . char) (mark) (point))
(meow--select))
(meow--select t))
(thread-first
(meow--make-selection '(expand . char) (point) (point))
(meow--select)))
(meow--select t)))
(meow--execute-kbd-macro meow--kbd-forward-char))

(defun meow-prev (arg)
@@ -762,10 +779,10 @@ See `meow-prev-line' for how prefix arguments work."
(if (region-active-p)
(thread-first
(meow--make-selection '(expand . char) (mark) (point))
(meow--select))
(meow--select t))
(thread-first
(meow--make-selection '(expand . char) (point) (point))
(meow--select)))
(meow--select t)))
(cond
((meow--with-universal-argument-p arg)
(goto-char (point-min)))
@@ -781,10 +798,10 @@ See `meow-next-line' for how prefix arguments work."
(if (region-active-p)
(thread-first
(meow--make-selection '(expand . char) (mark) (point))
(meow--select))
(meow--select t))
(thread-first
(meow--make-selection '(expand . char) (point) (point))
(meow--select)))
(meow--select t)))
(cond
((meow--with-universal-argument-p arg)
(goto-char (point-max)))
@@ -814,7 +831,7 @@ highlighted in the buffer."
(when beg
(thread-first
(meow--make-selection (cons 'expand type) beg end)
(meow--select backward))
(meow--select t backward))
(when (stringp regexp-format)
(let ((search (format regexp-format (regexp-quote (buffer-substring-no-properties beg end)))))
(meow--push-search search)
@@ -910,7 +927,7 @@ If N is negative, select to the beginning of the previous Nth thing instead."
(meow--fix-thing-selection-mark thing p m include-syntax)
p
expand)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions
(cons (apply-partially #'meow--backward-thing-1 thing)
(apply-partially #'meow--forward-thing-1 thing))))))
@@ -1010,7 +1027,7 @@ numeric, repeat times.
(setq p (line-beginning-position)))))
(thread-first
(meow--make-selection '(expand . line) orig p expand)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions '(meow--backward-line-1 . meow--forward-line-1))))
(t
(let ((m (if forward
@@ -1029,7 +1046,7 @@ numeric, repeat times.
(line-beginning-position))))))
(thread-first
(meow--make-selection '(expand . line) m p expand)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions '(meow--backward-line-1 . meow--forward-line-1)))))))

(defun meow-line-expand (n)
@@ -1058,7 +1075,7 @@ This command will expand line selection."
(meow--make-selection '(expand . line)
(if (and expand rbeg) (min rbeg beg) beg)
(if (and expand rend) (max rend end) end))
(meow--select (> orig-p beg)))
(meow--select t (> orig-p beg)))
(recenter)))

;; visual line versions
@@ -1115,7 +1132,7 @@ numeric, repeat times.
(setq p (meow--visual-line-beginning-position)))))
(thread-first
(meow--make-selection '(expand . line) orig p expand)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions '(meow--backward-visual-line-1 . meow--forward-visual-line-1))))
(t
(let ((m (if forward
@@ -1133,7 +1150,7 @@ numeric, repeat times.
(meow--visual-line-beginning-position))))))
(thread-first
(meow--make-selection '(expand . line) m p expand)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions '(meow--backward-visual-line-1 . meow--forward-visual-line-1)))))))

(defun meow-visual-line-expand (n)
@@ -1189,7 +1206,7 @@ numeric, repeat times.
(when (and p m)
(thread-first
(meow--make-selection '(expand . block) m p)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions '(meow--backward-block . meow--forward-block)))))

(defun meow-to-block (arg)
@@ -1216,7 +1233,7 @@ Will create selection with type (expand . block)."
(when (and p m)
(thread-first
(meow--make-selection '(expand . block) orig-pos p t)
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions '(meow--backward-block . meow--forward-block)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1233,7 +1250,7 @@ Will create selection with type (expand . block)."
(when pos
(thread-first
(meow--make-selection '(expand . join) pos mark)
(meow--select)))))
(meow--select t)))))

(defun meow--join-backward ()
(let* (mark
@@ -1247,7 +1264,7 @@ Will create selection with type (expand . block)."
(setq mark (point)))
(thread-first
(meow--make-selection '(expand . join) mark pos)
(meow--select))))
(meow--select t))))

(defun meow--join-both ()
(let* (mark
@@ -1262,7 +1279,7 @@ Will create selection with type (expand . block)."
(setq pos (point)))
(thread-first
(meow--make-selection '(expand . join) mark pos)
(meow--select))))
(meow--select t))))

(defun meow-join (arg)
"Select the indentation between this line to the non empty previous line.
@@ -1333,7 +1350,7 @@ with UNIVERSAL ARGUMENT, search both side."
(thread-first
(meow--make-selection '(select . find)
beg end expand)
(meow--select))
(meow--select t))
(setq meow--last-find ch)
(meow--maybe-highlight-num-positions
'(meow--find-continue-backward . meow--find-continue-forward)))))
@@ -1358,7 +1375,7 @@ with UNIVERSAL ARGUMENT, search both side."
(thread-first
(meow--make-selection '(select . till)
beg (+ end fix-pos) expand)
(meow--select))
(meow--select t))
(setq meow--last-till ch)
(meow--maybe-highlight-num-positions
'(meow--till-continue-backward . meow--till-continue-forward)))))
@@ -1409,7 +1426,7 @@ To search backward, use \\[negative-argument]."
(end (if reverse (marker-position marker-beg) (marker-position marker-end))))
(thread-first
(meow--make-selection '(select . visit) beg end)
(meow--select))
(meow--select t))
(if reverse
(message "Reverse search: %s" search)
(message "Search: %s" search))
@@ -1464,7 +1481,7 @@ To search backward, use \\[negative-argument]."
(end (if (> pos visit-point) (marker-position marker-beg) (marker-position marker-end))))
(thread-first
(meow--make-selection '(select . visit) beg end)
(meow--select))
(meow--select t))
(meow--push-search text)
(meow--ensure-visible)
(meow--highlight-regexp-in-buffer text)
@@ -1497,7 +1514,7 @@ To search backward, use \\[negative-argument]."
(meow--make-selection '(select . transient)
(if back (point) (car bounds))
(if back (car bounds) (point)))
(meow--select))))))
(meow--select t))))))

(defun meow-end-of-thing (thing)
"Select to the end of THING."
@@ -1510,15 +1527,15 @@ To search backward, use \\[negative-argument]."
(meow--make-selection '(select . transient)
(if back (cdr bounds) (point))
(if back (point) (cdr bounds)))
(meow--select))))))
(meow--select t))))))

(defun meow--select-range (back bounds)
(when bounds
(thread-first
(meow--make-selection '(select . transient)
(if back (cdr bounds) (car bounds))
(if back (car bounds) (cdr bounds)))
(meow--select))))
(meow--select t))))

(defun meow-inner-of-thing (thing)
"Select inner (excluding delimiters) of THING."
@@ -1650,7 +1667,7 @@ Argument ARG if not nil, switching in a new window."
(car meow--expand-nav-function)
(cdr meow--expand-nav-function)))))
(point)))
(meow--select))
(meow--select t))
(meow--maybe-highlight-num-positions meow--expand-nav-function)))))

(defun meow-expand-1 () (interactive) (meow-expand 1))
@@ -1701,7 +1718,7 @@ Argument ARG if not nil, switching in a new window."
(goto-char (overlay-start ov))
(thread-first
(meow--make-selection 'line (line-end-position) (line-beginning-position))
(meow--select))
(meow--select t))
(call-last-kbd-macro)
(delete-overlay ov))))))

@@ -1725,7 +1742,7 @@ Use negative argument for backward application."
(if back
(match-end 0)
(point)))
(meow--select))
(meow--select t))
(let ((ov (make-overlay (region-beginning) (region-end))))
(unwind-protect
(progn
8 changes: 3 additions & 5 deletions meow-core.el
Original file line number Diff line number Diff line change
@@ -43,15 +43,13 @@
(if meow-insert-mode
(run-hooks 'meow-insert-enter-hook)
(when (and meow--insert-pos
(or meow-select-on-change
meow-select-on-append
meow-select-on-insert)
(not (= (point) meow--insert-pos)))
(thread-first
(meow--make-selection '(select . transient) meow--insert-pos (point))
(meow--select)))
(meow--select meow--insert-activate-mark)))
(run-hooks 'meow-insert-exit-hook)
(setq-local meow--insert-pos nil)))
(setq-local meow--insert-pos nil
meow--insert-activate-mark nil)))

(meow-define-state normal
"Meow NORMAL state minor mode."
10 changes: 10 additions & 0 deletions meow-var.el
Original file line number Diff line number Diff line change
@@ -101,6 +101,13 @@ This doesn't affect how keypad works on recording or executing a kmacro."
:group 'meow
:type 'boolean)

(defcustom meow-select-on-open nil
"Whether to activate region when exiting INSERT mode after
`meow-open-above', `meow-open-below',`meow-open-above-visual' and
`meow-open-below-visual'."
:group 'meow
:type 'boolean)

(defcustom meow-expand-hint-remove-delay 1.0
"The delay before the position hint disappears."
:group 'meow
@@ -605,6 +612,9 @@ The value can be nil, quick or record.")
(defvar-local meow--insert-pos nil
"The position where we enter INSERT state.")

(defvar-local meow--insert-activate-mark nil
"Whether we should activate the selection after exiting INSERT state.")

(defvar meow-full-width-number-position-chars
'((0 . "")
(1 . "")

Unchanged files with check annotations Beta

(setq meow-keypad-describe-keymap-function 'meow-describe-keymap
meow-keypad-clear-describe-keymap-function nil
which-key-use-C-h-commands t)))

Check warning on line 407 in meow-shims.el

GitHub Actions / check (27.1, true)

assignment to free variable ‘which-key-use-C-h-commands’

Check warning on line 407 in meow-shims.el

GitHub Actions / check (28.2, true)

assignment to free variable ‘which-key-use-C-h-commands’
(defun meow--setup-which-key (enable)
"Setup which-key.
(meow--setup-eldoc t)
(meow--setup-rectangle-mark t)
(eval-after-load "macrostep" (lambda () (meow--setup-macrostep t)))

Check warning on line 543 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 543 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "wdired" (lambda () (meow--setup-wdired t)))

Check warning on line 544 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 544 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "edebug" (lambda () (meow--setup-edebug t)))

Check warning on line 545 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 545 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "magit" (lambda () (meow--setup-magit t)))

Check warning on line 546 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 546 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "wgrep" (lambda () (meow--setup-wgrep t)))

Check warning on line 547 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 547 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "company" (lambda () (meow--setup-company t)))

Check warning on line 548 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 548 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "corfu" (lambda () (meow--setup-corfu t)))

Check warning on line 549 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 549 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "polymode" (lambda () (meow--setup-polymode t)))

Check warning on line 550 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 550 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "cider" (lambda () (meow--setup-cider t)))

Check warning on line 551 in meow-shims.el

GitHub Actions / check (27.1, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.

Check warning on line 551 in meow-shims.el

GitHub Actions / check (28.2, true)

`eval-after-load' is for use in configurations, and should rarely be used in packages.
(eval-after-load "sly" (lambda () (meow--setup-sly t)))
(eval-after-load "realgud" (lambda () (meow--setup-realgud t)))
(eval-after-load "which-key" (lambda () (meow--setup-which-key t)))