emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/with-editor 391e76a256 2/2: Teach sleeping editor about "+


From: ELPA Syncer
Subject: [nongnu] elpa/with-editor 391e76a256 2/2: Teach sleeping editor about "+L[:C]" argument preceding filename
Date: Wed, 18 Jan 2023 13:01:46 -0500 (EST)

branch: elpa/with-editor
commit 391e76a256aeec6b9e4cbd733088f30c677d965b
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Teach sleeping editor about "+L[:C]" argument preceding filename
    
    Closes #120.
---
 docs/with-editor.org |  4 ++--
 lisp/with-editor.el  | 43 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/docs/with-editor.org b/docs/with-editor.org
index d1c1a32c02..3e7032ff7a 100644
--- a/docs/with-editor.org
+++ b/docs/with-editor.org
@@ -120,14 +120,14 @@ it receives a signal.
 
   #+BEGIN_SRC emacs-lisp
     "sh -c '\
-    echo \"WITH-EDITOR: $$ OPEN $0 IN $(pwd)\"; \
+    echo \"WITH-EDITOR: $$ OPEN $0$1 IN $(pwd)\"; \
     trap \"exit 0\" USR1; \
     trap \"exit 1\" USR2; \
     while true; do sleep 1; done'"
   #+END_SRC
 
   Note that the unit separator character () right after the file
-  name ($0) is required.
+  name ($0) is required. TODO
 
   Also note that using this alternative implementation leads to a
   delay of up to a second.  The delay can be shortened by replacing
diff --git a/lisp/with-editor.el b/lisp/with-editor.el
index 02b8f2d69d..990aae6dbb 100644
--- a/lisp/with-editor.el
+++ b/lisp/with-editor.el
@@ -168,7 +168,7 @@ please see 
https://github.com/magit/magit/wiki/Emacsclient.";))))
 
 (defcustom with-editor-sleeping-editor "\
 sh -c '\
-printf \"\\nWITH-EDITOR: $$ OPEN $0\\037 IN $(pwd)\\n\"; \
+printf \"\\nWITH-EDITOR: $$ OPEN $0\\037$1\\037 IN $(pwd)\\n\"; \
 sleep 604800 & sleep=$!; \
 trap \"kill $sleep; exit 0\" USR1; \
 trap \"kill $sleep; exit 1\" USR2; \
@@ -197,13 +197,16 @@ with \"bash\" (and install that), or you can use the 
older, less
 performant implementation:
 
   \"sh -c '\\
-  echo -e \\\"\\nWITH-EDITOR: $$ OPEN $0 IN $(pwd)\\n\\\"; \\
+  echo -e \\\"\\nWITH-EDITOR: $$ OPEN $0$1 IN $(pwd)\\n\\\"; \\
   trap \\\"exit 0\\\" USR1; \\
   trap \\\"exit 1\" USR2; \\
   while true; do sleep 1; done'\"
 
-Note that the unit separator character () right after the file
-name ($0) is required.
+Note that the two unit separator characters () right after $0
+and $1 are required.  Normally $0 is the file name and $1 is
+missing or else gets ignored.  But if $0 has the form \"+N[:N]\",
+then it is treated as a position in the file and $1 is expected
+to be the file.
 
 Also note that using this alternative implementation leads to a
 delay of up to a second.  The delay can be shortened by replacing
@@ -634,8 +637,11 @@ may not insert the text into the PROCESS's buffer.  Then 
it calls
 
 (defvar with-editor-filter-visit-hook nil)
 
-(defconst with-editor-sleeping-editor-regexp
-  "^WITH-EDITOR: \\([0-9]+\\) OPEN \\([^]+?\\)\\(?: IN 
\\([^\r]+?\\)\\)?\r?$")
+(defconst with-editor-sleeping-editor-regexp "^\
+WITH-EDITOR: \\([0-9]+\\) \
+OPEN \\([^]+?\\)\
+\\(?:\\([^]*\\)\\)?\
+\\(?: IN \\([^\r]+?\\)\\)?\r?$")
 
 (defvar with-editor--max-incomplete-length 1000)
 
@@ -656,8 +662,16 @@ may not insert the text into the PROCESS's buffer.  Then 
it calls
       (when process
         (process-put process 'incomplete nil))
       (let ((pid  (match-string 1 string))
-            (file (match-string 2 string))
-            (dir  (match-string 3 string)))
+            (arg0 (match-string 2 string))
+            (arg1 (match-string 3 string))
+            (dir  (match-string 4 string))
+            file line column)
+        (cond ((string-match "\\`\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?\\'" 
arg0)
+               (setq file arg1)
+               (setq line (string-to-number (match-string 1 arg0)))
+               (setq column (match-string 2 arg0))
+               (setq column (and column (string-to-number column))))
+              ((setq file arg0)))
         (unless (file-name-absolute-p file)
           (setq file (expand-file-name file dir)))
         (when default-directory
@@ -667,6 +681,19 @@ may not insert the text into the PROCESS's buffer.  Then 
it calls
           (setq with-editor--pid pid)
           (setq with-editor-previous-winconf
                 (current-window-configuration))
+          (when line
+            (let ((pos (save-excursion
+                         (save-restriction
+                           (goto-char (point-min))
+                           (forward-line (1- line))
+                           (when column
+                             (move-to-column column))
+                           (point)))))
+              (when (and (buffer-narrowed-p)
+                         widen-automatically
+                         (not (<= (point-min) pos (point-max))))
+                (widen))
+              (goto-char pos)))
           (run-hooks 'with-editor-filter-visit-hook)
           (funcall (or (with-editor-server-window) #'switch-to-buffer)
                    (current-buffer))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]