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

Allow custom delete-region, insert functions #609

Merged
merged 1 commit into from
Oct 5, 2024
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
2 changes: 1 addition & 1 deletion meow-beacon.el
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ The recorded kmacro will be applied to all cursors immediately."
(delete-overlay ov)))))))

(defun meow--beacon-delete-region ()
(delete-region (region-beginning) (region-end)))
(meow--delete-region (region-beginning) (region-end)))

(defun meow-beacon-kill-delete ()
"Delete all selections.
Expand Down
28 changes: 14 additions & 14 deletions meow-command.el
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
(meow--with-selection-fallback
(cond
((equal '(expand . join) (meow--selection-type))
(delete-indentation nil (region-beginning) (region-end)))

Check warning on line 259 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

delete-indentation called with 3 arguments, but accepts only 0-1
(t
(meow--prepare-region-for-kill)
(meow--execute-kbd-macro meow--kbd-kill-region)))))))
Expand All @@ -271,11 +271,11 @@
(meow--with-selection-fallback
(cond
((equal '(expand . join) (meow--selection-type))
(delete-indentation nil (region-beginning) (region-end)))

Check warning on line 274 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (26.3, true)

delete-indentation called with 3 arguments, but accepts only 0-1
(t
(meow--prepare-region-for-kill)
(let ((s (buffer-substring-no-properties (region-beginning) (region-end))))
(delete-region (region-beginning) (region-end))
(meow--delete-region (region-beginning) (region-end))
(kill-append (meow--prepare-string-for-kill-append s) nil))))))))

(defun meow-C-k ()
Expand Down Expand Up @@ -465,7 +465,7 @@
(save-mark-and-excursion
(newline))
;; (save-mark-and-excursion
;; (insert "\n"))
;; (meow--insert "\n"))
(indent-according-to-mode)))

(defun meow-open-above-visual ()
Expand Down Expand Up @@ -511,7 +511,7 @@
(when (meow--allow-modify-p)
(setq this-command #'meow-change)
(meow--with-selection-fallback
(delete-region (region-beginning) (region-end))
(meow--delete-region (region-beginning) (region-end))
(meow--switch-state 'insert)
(setq-local meow--insert-pos (point)))))

Expand Down Expand Up @@ -540,19 +540,19 @@
(let ((select-enable-clipboard meow-use-clipboard))
(when (meow--allow-modify-p)
(when-let ((s (string-trim-right (current-kill 0 t) "\n")))
(delete-region (region-beginning) (region-end))
(meow--delete-region (region-beginning) (region-end))
(set-marker meow--replace-start-marker (point))
(insert s))))))
(meow--insert s))))))

(defun meow-replace-char ()
"Replace current char with selection."
(interactive)
(let ((select-enable-clipboard meow-use-clipboard))
(when (< (point) (point-max))
(when-let ((s (string-trim-right (current-kill 0 t) "\n")))
(delete-region (point) (1+ (point)))
(meow--delete-region (point) (1+ (point)))
(set-marker meow--replace-start-marker (point))
(insert s)))))
(meow--insert s)))))

(defun meow-replace-save ()
(interactive)
Expand All @@ -566,12 +566,12 @@
(meow--prepare-region-for-kill)
(buffer-substring-no-properties (region-beginning) (region-end)))))
(progn
(delete-region (region-beginning) (region-end))
(meow--delete-region (region-beginning) (region-end))
(set-marker meow--replace-start-marker (point))
(insert s)
(meow--insert s)
(kill-new old)))
(set-marker meow--replace-start-marker (point))
(insert s)))))))
(meow--insert s)))))))

(defun meow-replace-pop ()
"Like `yank-pop', but for `meow-replace'.
Expand Down Expand Up @@ -599,9 +599,9 @@
(message "`meow-replace-pop': Reached end of kill ring"))
(let ((txt (string-trim-right (current-kill meow--replace-pop-index t)
"\n")))
(delete-region meow--replace-start-marker (point))
(meow--delete-region meow--replace-start-marker (point))
(set-marker meow--replace-start-marker (point))
(insert txt))))
(meow--insert txt))))
(setq this-command 'meow-replace-pop))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -1292,7 +1292,7 @@
;;; VISIT and SEARCH
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun meow-search (arg)

Check warning on line 1295 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

docstring wider than 80 characters
" Search and select with the car of current `regexp-search-ring'.

If the contents of selection doesn't match the regexp, will push it to `regexp-search-ring' before searching.
Expand Down Expand Up @@ -1355,7 +1355,7 @@
(or (funcall func text nil t 1)
(funcall func-2 text nil t 1)))))

(defun meow-visit (arg)

Check warning on line 1358 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (28.2, true)

docstring wider than 80 characters
"Read a string from minibuffer, then find and select it.

The input will be pushed into `regexp-search-ring'. So
Expand Down Expand Up @@ -1726,8 +1726,8 @@
(region-str (when (region-active-p) (buffer-substring-no-properties rbeg rend)))
(sel-str (meow--second-sel-get-string))
(next-marker (make-marker)))
(when region-str (delete-region rbeg rend))
(when sel-str (insert sel-str))
(when region-str (meow--delete-region rbeg rend))
(when sel-str (meow--insert sel-str))
(move-marker next-marker (point))
(meow--second-sel-set-string (or region-str ""))
(when (overlayp mouse-secondary-overlay)
Expand Down Expand Up @@ -1757,8 +1757,8 @@
(cmd (key-binding key)))
(if-let ((dispatch (and (commandp cmd)
(get cmd 'meow-dispatch))))
(describe-key (kbd dispatch) buffer up-event)

Check warning on line 1760 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

describe-key called with 3 arguments, but accepts only 1-2
(describe-key key-list buffer up-event)))

Check warning on line 1761 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

describe-key called with 3 arguments, but accepts only 1-2

Check warning on line 1761 in meow-command.el

View workflow job for this annotation

GitHub Actions / check (27.1, true)

describe-key called with 3 arguments, but accepts only 1-2
;; for mouse events
(describe-key key-list buffer up-event)))

Expand Down Expand Up @@ -1789,3 +1789,3 @@

(provide 'meow-command)
;;; meow-command.el ends here
16 changes: 12 additions & 4 deletions meow-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ Looks up the state in meow-replace-state-name-list"
(when-let ((bounds (bounds-of-thing-at-point thing)))
(cons type bounds)))

(defun meow--insert (&rest args)
"Use `meow--insert-function' to insert ARGS at point."
(apply meow--insert-function args))

(defun meow--delete-region (start end)
"Use `meow--delete-region-function' to delete text between START and END."
(funcall meow--delete-region-function start end))

(defun meow--push-search (search)
(unless (string-equal search (car regexp-search-ring))
(add-to-history 'regexp-search-ring search regexp-search-ring-max)))
Expand Down Expand Up @@ -419,7 +427,7 @@ Looks up the state in meow-replace-state-name-list"
(when (or (member this-command meow-grab-fill-commands)
(member meow--keypad-this-command meow-grab-fill-commands))
(when-let ((s (meow--second-sel-get-string)))
(insert s))))
(meow--insert s))))

(defun meow--parse-string-to-keypad-keys (str)
(let ((strs (split-string str " ")))
Expand Down Expand Up @@ -536,12 +544,12 @@ that bound to DEF. Otherwise, return DEF."
((meow--second-sel-buffer)
(with-current-buffer (overlay-buffer mouse-secondary-overlay)
(goto-char (overlay-start mouse-secondary-overlay))
(delete-region (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay))
(insert string)))
(meow--delete-region (overlay-start mouse-secondary-overlay) (overlay-end mouse-secondary-overlay))
(meow--insert string)))
((markerp mouse-secondary-start)
(with-current-buffer (marker-buffer mouse-secondary-start)
(goto-char (marker-position mouse-secondary-start))
(insert string)))))
(meow--insert string)))))

(defun meow--second-sel-get-string ()
(when (meow--second-sel-buffer)
Expand Down
11 changes: 11 additions & 0 deletions meow-var.el
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ Use (setq meow-keypad-describe-keymap-function 'nil) to disable popup.")
(defvar meow--kbd-goto-line "M-g g"
"KBD macro for command `goto-line'.")

(defvar meow--delete-region-function #'delete-region
"The function used to delete the selection.

Allows support of modes that define their own equivalent of
`delete-region'.")

(defvar meow--insert-function #'insert
"The function used to insert text in Normal state.

Allows support of modes that define their own equivalent of `insert'.")

(defvar-local meow--indicator nil
"Indicator for current buffer.")

Expand Down
Loading