Skip to content

Commit

Permalink
Add optional include-syntax to meow-next-thing, fix the behaviors of …
Browse files Browse the repository at this point in the history
…next/prev-word/symbol
  • Loading branch information
DogLooksGood committed Oct 23, 2024
1 parent 2d4c92f commit c0878ac
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions meow-command.el
Original file line number Diff line number Diff line change
Expand Up @@ -858,26 +858,34 @@ This command works similar to `meow-mark-word'."
(when (not (= pos (point)))
(point))))

(defun meow--fix-thing-selection-mark (thing pos mark)
(defun meow--fix-thing-selection-mark (thing pos mark include-syntax)
"Return new mark for a selection of THING.
This will shrink the word selection only contains
word/symbol constituent character and whitespaces."
(save-mark-and-excursion
(goto-char
(if (> mark pos) pos
;; Point must be before the end of the word to get the bounds correctly
(1- pos)))
(let ((bounds (bounds-of-thing-at-point thing)))
(if (> mark pos)
(min mark (cdr bounds))
(max mark (car bounds))))))

(defun meow-next-thing (thing type n)
those in INCLUDE-SYNTAX."
(let ((backward (> mark pos)))
(save-mark-and-excursion
(goto-char
(if backward pos
;; Point must be before the end of the word to get the bounds correctly
(1- pos)))
(let* ((bounds (bounds-of-thing-at-point thing))
(m (if backward
(min mark (cdr bounds))
(max mark (car bounds)))))
(save-mark-and-excursion
(goto-char m)
(if backward
(skip-syntax-forward include-syntax mark)
(skip-syntax-backward include-syntax mark))
(point))))))

(defun meow-next-thing (thing type n &optional include-syntax)
"Create non-expandable selection of TYPE to the end of the next Nth THING.
If N is negative, select to the beginning of the previous Nth thing instead."
(unless (equal type (cdr (meow--selection-type)))
(meow--cancel-selection))
(unless include-syntax (setq include-syntax "'w_ "))
(let* ((expand (equal (cons 'expand type) (meow--selection-type)))
(_ (when expand
(if (< n 0) (meow--direction-backward)
Expand All @@ -891,7 +899,10 @@ If N is negative, select to the beginning of the previous Nth thing instead."
(when p
(thread-first
(meow--make-selection
new-type (meow--fix-thing-selection-mark thing p m) p expand)
new-type
(meow--fix-thing-selection-mark thing p m include-syntax)
p
expand)
(meow--select))
(meow--maybe-highlight-num-positions
(cons (apply-partially #'meow--backward-thing-1 thing)
Expand Down Expand Up @@ -935,15 +946,15 @@ To select continuous symbols, use following approaches:
A non-expandable word selection will be created.
This command works similar to `meow-next-word'."
(interactive "p")
(meow-next-thing meow-word-thing 'word (- n)))
(meow-next-thing meow-word-thing 'word (- n) "_w "))

(defun meow-back-symbol (n)
"Select to the beginning the previous Nth symbol.
A non-expandable word selection will be created.
This command works similar to `meow-next-symbol'."
(interactive "p")
(meow-next-thing meow-symbol-thing 'symbol (- n)))
(meow-next-thing meow-symbol-thing 'symbol (- n) "_w "))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; LINE SELECTION
Expand Down

0 comments on commit c0878ac

Please sign in to comment.