From: Ivan Sokolov <ivan-p-sokolov@ya.ru>
To: emacs-devel@gnu.org
Subject: New command: move-past-close
Date: Sat, 06 Nov 2021 01:59:31 +0300 [thread overview]
Message-ID: <87v916w6ng.fsf@ya.ru> (raw)
[-- 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
next reply other threads:[~2021-11-05 22:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 22:59 Ivan Sokolov [this message]
2021-11-05 23:17 ` New command: move-past-close Andreas Schwab
2021-11-07 2:43 ` Ivan Sokolov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v916w6ng.fsf@ya.ru \
--to=ivan-p-sokolov@ya.ru \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).