* New command: move-past-close
@ 2021-11-05 22:59 Ivan Sokolov
2021-11-05 23:17 ` Andreas Schwab
0 siblings, 1 reply; 3+ messages in thread
From: Ivan Sokolov @ 2021-11-05 22:59 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 217 bytes --]
Recently found move-past-close-and-reindent, useful indeed, but I
usually don't need reindent functionality, so I added a non-indenting
command.
I also replaced nth/elt usages in lisp.el with proper ppss accessors.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-ppss-accessors-instead-of-nth-and-elt.patch --]
[-- Type: text/x-patch, Size: 4978 bytes --]
From d2d40fa3f071c2137ea7686114a550ec0bb7c2ff Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Sat, 6 Nov 2021 01:40:59 +0300
Subject: [PATCH 1/2] Use ppss accessors instead of nth and elt
* lisp/emacs-lisp/lisp.el: Use ppss accessors instead of nth and elt.
---
lisp/emacs-lisp/lisp.el | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 9b38d86e2c..e9932df8d0 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -227,13 +227,14 @@ up-list
;; string.
(when no-syntax-crossing
(let* ((syntax (syntax-ppss))
- (string-comment-start (nth 8 syntax)))
+ (string-comment-start
+ (ppss-comment-or-string-start syntax)))
(when string-comment-start
(save-excursion
(goto-char string-comment-start)
(narrow-to-region
(point)
- (if (nth 3 syntax) ; in string
+ (if (ppss-string-terminator syntax) ; in string
(condition-case nil
(progn (forward-sexp) (point))
(scan-error (point-max)))
@@ -258,8 +259,8 @@ up-list
;; or end of that string.
(and escape-strings
(or syntax (setf syntax (syntax-ppss)))
- (nth 3 syntax)
- (goto-char (nth 8 syntax))
+ (ppss-string-terminator syntax)
+ (goto-char (ppss-comment-or-string-start syntax))
(progn (when (> inc 0)
(forward-sexp))
t))
@@ -269,8 +270,8 @@ up-list
;; end of the comment.
(and no-syntax-crossing
(or syntax (setf syntax (syntax-ppss)))
- (nth 4 syntax)
- (goto-char (nth 8 syntax))
+ (ppss-comment-depth syntax)
+ (goto-char (ppss-comment-or-string-start syntax))
(or (< inc 0)
(forward-comment 1))
(setf arg (+ arg inc)))
@@ -407,7 +408,7 @@ beginning-of-defun-raw
"\\(?:" defun-prompt-regexp "\\)\\s(")
"^\\s(")
nil 'move arg))
- (nth 8 (syntax-ppss))))
+ (ppss-comment-or-string-start (syntax-ppss))))
found)
(progn (goto-char (1- (match-end 0)))
t)))
@@ -435,8 +436,8 @@ beginning-of-defun-raw
encl-pos)
;; Back out of any comment/string, so that encl-pos will always
;; become nil if we're at top-level.
- (when (nth 8 ppss)
- (goto-char (nth 8 ppss))
+ (when (ppss-comment-or-string-start ppss)
+ (goto-char (ppss-comment-or-string-start ppss))
(setq ppss (syntax-ppss))) ; should be fast, due to cache.
(setq encl-pos (syntax-ppss-toplevel-pos ppss))
(if encl-pos (goto-char encl-pos))
@@ -471,10 +472,10 @@ beginning-of-defun--in-emptyish-line-p
(save-excursion
(forward-line 0)
(let ((ppss (syntax-ppss)))
- (and (null (nth 3 ppss))
+ (and (null (ppss-string-terminator ppss))
(< (line-end-position)
- (progn (when (nth 4 ppss)
- (goto-char (nth 8 ppss)))
+ (progn (when (ppss-comment-depth ppss)
+ (goto-char (ppss-comment-or-string-start ppss)))
(forward-comment (point-max))
(point)))))))
@@ -486,9 +487,10 @@ beginning-of-defun-comments
(let (first-line-p)
(while (let ((ppss (progn (setq first-line-p (= (forward-line -1) -1))
(syntax-ppss (line-end-position)))))
- (while (and (nth 4 ppss) ; If eol is in a line-spanning comment,
- (< (nth 8 ppss) (line-beginning-position)))
- (goto-char (nth 8 ppss)) ; skip to comment start.
+ (while (and (ppss-comment-depth ppss) ; If eol is in a line-spanning comment,
+ (< (ppss-comment-or-string-start ppss)
+ (line-beginning-position)))
+ (goto-char (ppss-comment-or-string-start ppss)) ; skip to comment start.
(setq ppss (syntax-ppss (line-end-position))))
(and (not first-line-p)
(progn (skip-syntax-backward
@@ -893,7 +895,8 @@ move-past-close-and-reindent
(setq state (parse-partial-sexp (point) end nil nil
state))
;; Check not in string or comment.
- (and (not (elt state 3)) (not (elt state 4))))))))
+ (and (not (ppss-string-terminator state))
+ (not (ppss-comment-depth state))))))))
(delete-indentation))
(forward-char 1)
(newline-and-indent))
--
2.33.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Add-move-past-close.patch --]
[-- Type: text/x-patch, Size: 1766 bytes --]
From 64256cf84a67c5109b1e9e8603ebf2cecdb515fa Mon Sep 17 00:00:00 2001
From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
Date: Sat, 6 Nov 2021 01:54:01 +0300
Subject: [PATCH 2/2] Add move-past-close
* lisp/emacs-lisp/lisp.el: add move-past-close.
---
lisp/emacs-lisp/lisp.el | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index e9932df8d0..606a3be425 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -872,6 +872,12 @@ raise-sexp
(defun move-past-close-and-reindent ()
"Move past next `)', delete indentation before it, then indent after it."
(interactive)
+ (move-past-close)
+ (newline-and-indent))
+
+(defun move-past-close ()
+ "Move past next `)' and delete indentation before it."
+ (interactive)
(up-list 1)
(forward-char -1)
(while (save-excursion ; this is my contribution
@@ -887,10 +893,10 @@ move-past-close-and-reindent
state)
(beginning-of-line)
;; Get state at start of line.
- (setq state (list 0 nil nil
- (null (calculate-lisp-indent))
- nil nil nil nil
- nil))
+ (setq state
+ (make-ppss
+ :depth 0
+ :string-terminator (null (calculate-lisp-indent))))
;; Parse state across the line to get state at end.
(setq state (parse-partial-sexp (point) end nil nil
state))
@@ -898,8 +904,7 @@ move-past-close-and-reindent
(and (not (ppss-string-terminator state))
(not (ppss-comment-depth state))))))))
(delete-indentation))
- (forward-char 1)
- (newline-and-indent))
+ (forward-char 1))
(defun check-parens () ; lame name?
"Check for unbalanced parentheses in the current buffer.
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: New command: move-past-close
2021-11-05 22:59 New command: move-past-close Ivan Sokolov
@ 2021-11-05 23:17 ` Andreas Schwab
2021-11-07 2:43 ` Ivan Sokolov
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2021-11-05 23:17 UTC (permalink / raw)
To: Ivan Sokolov; +Cc: emacs-devel
On Nov 06 2021, Ivan Sokolov wrote:
> diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
> index e9932df8d0..606a3be425 100644
> --- a/lisp/emacs-lisp/lisp.el
> +++ b/lisp/emacs-lisp/lisp.el
> @@ -872,6 +872,12 @@ raise-sexp
> (defun move-past-close-and-reindent ()
> "Move past next `)', delete indentation before it, then indent after it."
> (interactive)
> + (move-past-close)
> + (newline-and-indent))
> +
> +(defun move-past-close ()
> + "Move past next `)' and delete indentation before it."
That's not a good name, since it does more than moving.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: New command: move-past-close
2021-11-05 23:17 ` Andreas Schwab
@ 2021-11-07 2:43 ` Ivan Sokolov
0 siblings, 0 replies; 3+ messages in thread
From: Ivan Sokolov @ 2021-11-07 2:43 UTC (permalink / raw)
To: Andreas Schwab; +Cc: emacs-devel
Andreas Schwab <schwab@linux-m68k.org> writes:
> That's not a good name, since it does more than moving.
You are right, but I cannot think of how to alter the code or name.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-07 2:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-05 22:59 New command: move-past-close Ivan Sokolov
2021-11-05 23:17 ` Andreas Schwab
2021-11-07 2:43 ` Ivan Sokolov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.