Skip to content

Commit

Permalink
add custom variable meow-thing-selection-directions
Browse files Browse the repository at this point in the history
  • Loading branch information
tianshu committed Dec 10, 2021
1 parent 3714ab8 commit 8101430
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ register new thing with Emacs things, functions, syntax descriptions or regexp p
- A helper function `meow-thing-register` is provided, check its document for usage.
- Thing `indent` and `extend` has been removed.
- Variable `meow-extend-syntax`(undocumented) has been removed.
- `meow-inner-of-thing` will create a backward selection.
- Add custom variable `meow-thing-selection-directions`.
- `meow-bounds-of-thing` will create a backward selection by default.

### Enhancements
* Remove paredit shims, no longer needed.
Expand Down
33 changes: 21 additions & 12 deletions meow-command.el
Original file line number Diff line number Diff line change
Expand Up @@ -1197,19 +1197,25 @@ Argument ARG if not nil, reverse the selection when making selection."
(concat (meow--render-char-thing-table) "\n" prompt-text)
prompt-text)))

(defun meow--thing-get-direction (cmd)
(or
(alist-get cmd meow-thing-selection-directions)
'forward))

(defun meow-beginning-of-thing ()
"Select to the beginning of thing represented by CH.
When EXPAND is non-nil, extend current selection.
Prefix argument is not allowed for this command."
(interactive)
(save-window-excursion
(let ((bounds (meow--parse-inner-of-thing-char
(let ((back (equal 'backward (meow--thing-get-direction 'beginning)))
(bounds (meow--parse-inner-of-thing-char
(meow-thing-prompt "Beginning of:"))))
(when bounds
(-> (meow--make-selection '(select . transient)
(point)
(car bounds))
(if back (point) (car bounds))
(if back (car bounds) (point)))
(meow--select))))))

(defun meow-end-of-thing ()
Expand All @@ -1219,34 +1225,37 @@ When EXPAND is non-nil, extend current selection.
Prefix argument is not allowed for this command."
(interactive)
(save-window-excursion
(let ((bounds (meow--parse-inner-of-thing-char
(let ((back (equal 'backward (meow--thing-get-direction 'end)))
(bounds (meow--parse-inner-of-thing-char
(meow-thing-prompt "End of:"))))
(when bounds
(-> (meow--make-selection '(select . transient)
(point)
(cdr bounds))
(if back (cdr bounds) (point))
(if back (point) (cdr bounds)))
(meow--select))))))

(defun meow-inner-of-thing ()
(interactive)
(save-window-excursion
(let ((bounds (meow--parse-inner-of-thing-char
(let ((back (equal 'backward (meow--thing-get-direction 'inner)))
(bounds (meow--parse-inner-of-thing-char
(meow-thing-prompt "Inner of:"))))
(when bounds
(-> (meow--make-selection '(select . transient)
(cdr bounds)
(car bounds))
(if back (cdr bounds) (car bounds))
(if back (car bounds) (cdr bounds)))
(meow--select))))))

(defun meow-bounds-of-thing ()
(interactive)
(save-window-excursion
(let ((bounds (meow--parse-bounds-of-thing-char
(let ((back (equal 'backward (meow--thing-get-direction 'bounds)))
(bounds (meow--parse-bounds-of-thing-char
(meow-thing-prompt "Bounds of:"))))
(when bounds
(-> (meow--make-selection '(select . transient)
(car bounds)
(cdr bounds))
(if back (cdr bounds) (car bounds))
(if back (car bounds) (cdr bounds)))
(meow--select))))))

(defun meow-indent ()
Expand Down
11 changes: 10 additions & 1 deletion meow-var.el
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,19 @@ This will affect how selection is displayed."
:group 'meow
:type 'list)

(defcustom meow-thing-selection-directions
'((inner . forward)
(bounds . backward)
(beginning . backward)
(end . forward))
"Selection directions for each thing command."
:group 'meow
:type 'list)

(defcustom meow-display-thing-help t
"Whether to display the help prompt for meow-inner/bounds/begin/end-of-thing."
:group 'meow
:type :boolean)
:type 'boolean)

(defcustom meow-keypad-describe-delay
0.5
Expand Down

0 comments on commit 8101430

Please sign in to comment.