[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/meow fb61ce5943: Add visual-line versions of some MEOW ope
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/meow fb61ce5943: Add visual-line versions of some MEOW operations/entities (#416) |
Date: |
Sun, 19 Mar 2023 00:01:09 -0400 (EDT) |
branch: elpa/meow
commit fb61ce5943d7ad11f4a7350e4b561947bbbaea71
Author: Benjamin Slade <slade@jnanam.net>
Commit: GitHub <noreply@github.com>
Add visual-line versions of some MEOW operations/entities (#416)
- `meow-visual-line` as visual-line counterpart to `meow-line`
- `visual-line` as a new 'meow-thing
- `meow-open-below-visual` as visual-line counterpart to `meow-open-below`
- `meow-open-above-visual` as visual-line counterpart to `meow-open-above`
---
meow-command.el | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
meow-thing.el | 6 ++++
meow-var.el | 1 +
3 files changed, 112 insertions(+)
diff --git a/meow-command.el b/meow-command.el
index 13602c6ffd..978e7ae44c 100644
--- a/meow-command.el
+++ b/meow-command.el
@@ -468,6 +468,19 @@ This command supports `meow-selection-command-fallback'."
;; (insert "\n"))
(indent-according-to-mode)))
+(defun meow-open-above-visual ()
+ "Open a newline above and switch to INSERT state."
+ (interactive)
+ (if meow--temp-normal
+ (progn
+ (message "Quit temporary normal mode")
+ (meow--switch-state 'motion))
+ (meow--switch-state 'insert)
+ (goto-char (meow--visual-line-beginning-position))
+ (save-mark-and-excursion
+ (newline))
+ (indent-according-to-mode)))
+
(defun meow-open-below ()
"Open a newline below and switch to INSERT state."
(interactive)
@@ -479,6 +492,17 @@ This command supports `meow-selection-command-fallback'."
(goto-char (line-end-position))
(meow--execute-kbd-macro "RET")))
+(defun meow-open-below-visual ()
+ "Open a newline below and switch to INSERT state."
+ (interactive)
+ (if meow--temp-normal
+ (progn
+ (message "Quit temporary normal mode")
+ (meow--switch-state 'motion))
+ (meow--switch-state 'insert)
+ (goto-char (meow--visual-line-end-position))
+ (meow--execute-kbd-macro "RET")))
+
(defun meow-change ()
"Kill current selection and switch to INSERT state.
@@ -944,6 +968,87 @@ This command will expand line selection."
(meow--select (> orig-p beg)))
(recenter)))
+;; visual line versions
+(defun meow--visual-line-beginning-position ()
+ (save-excursion
+ (beginning-of-visual-line)
+ (point)))
+
+(defun meow--visual-line-end-position ()
+ (save-excursion
+ (end-of-visual-line)
+ (point)))
+
+(defun meow--forward-visual-line-1 ()
+ (let ((orig (point)))
+ (line-move-visual 1)
+ (if meow--expanding-p
+ (progn
+ (goto-char (meow--visual-line-end-position))
+ (meow--visual-line-end-position))
+ (when (< orig (meow--visual-line-beginning-position))
+ (meow--visual-line-beginning-position)))))
+
+(defun meow--backward-visual-line-1 ()
+ (line-move-visual -1)
+ (meow--visual-line-beginning-position))
+
+(defun meow-visual-line (n &optional expand)
+ "Select the current visual line, eol is not included.
+
+Create selection with type (expand . line).
+For the selection with type (expand . line), expand it by line.
+For the selection with other types, cancel it.
+
+Prefix:
+numeric, repeat times.
+"
+ (interactive "p")
+ (unless (or expand (equal '(expand . line) (meow--selection-type)))
+ (meow--cancel-selection))
+ (let* ((orig (mark t))
+ (n (if (meow--direction-backward-p)
+ (- n)
+ n))
+ (forward (> n 0)))
+ (cond
+ ((region-active-p)
+ (let (p)
+ (save-mark-and-excursion
+ (line-move-visual n)
+ (goto-char
+ (if forward
+ (setq p (meow--visual-line-end-position))
+ (setq p (meow--visual-line-beginning-position)))))
+ (thread-first
+ (meow--make-selection '(expand . line) orig p expand)
+ (meow--select))
+ (meow--maybe-highlight-num-positions '(meow--backward-visual-line-1 .
meow--forward-visual-line-1))))
+ (t
+ (let ((m (if forward
+ (meow--visual-line-beginning-position)
+ (meow--visual-line-end-position)))
+ (p (save-mark-and-excursion
+ (if forward
+ (progn
+ (line-move-visual (1- n))
+ (meow--visual-line-end-position))
+ (progn
+ (line-move-visual (1+ n))
+ (when (meow--empty-line-p)
+ (backward-char 1))
+ (meow--visual-line-beginning-position))))))
+ (thread-first
+ (meow--make-selection '(expand . line) m p expand)
+ (meow--select))
+ (meow--maybe-highlight-num-positions '(meow--backward-visual-line-1 .
meow--forward-visual-line-1)))))))
+
+(defun meow-visual-line-expand (n)
+ "Like `meow-line', but always expand."
+ (interactive "p")
+ (meow-visual-line n t))
+
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; BLOCK
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/meow-thing.el b/meow-thing.el
index 1b65eb742d..c8bd070f8e 100644
--- a/meow-thing.el
+++ b/meow-thing.el
@@ -82,6 +82,10 @@ The thing `string' is not available in Emacs 27.'"
(cons (save-mark-and-excursion (back-to-indentation) (point))
(line-end-position)))
+(defun meow--inner-of-visual-line ()
+ (cons (meow--visual-line-beginning-position)
+ (meow--visual-line-end-position)))
+
;;; Registry
(defvar meow--thing-registry nil
@@ -314,6 +318,8 @@ PAIR-EXPR contains two string token lists. The tokens in
first
(meow-thing-register 'line #'meow--inner-of-line 'line)
+(meow-thing-register 'visual-line #'meow--inner-of-visual-line
#'meow--inner-of-visual-line)
+
(defun meow--parse-inner-of-thing-char (ch)
(when-let ((ch-to-thing (assoc ch meow-char-thing-table)))
(meow--parse-range-of-thing (cdr ch-to-thing) t)))
diff --git a/meow-var.el b/meow-var.el
index 7466a3fc9c..f6b364de14 100644
--- a/meow-var.el
+++ b/meow-var.el
@@ -118,6 +118,7 @@ This will affect how selection is displayed."
(?b . buffer)
(?p . paragraph)
(?l . line)
+ (?v . visual-line)
(?d . defun)
(?. . sentence))
"Mapping from char to thing."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/meow fb61ce5943: Add visual-line versions of some MEOW operations/entities (#416),
ELPA Syncer <=