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

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

[nongnu] elpa/with-editor 71e61b9 081/140: with-editor-sleeping-editor:


From: Jonas Bernoulli
Subject: [nongnu] elpa/with-editor 71e61b9 081/140: with-editor-sleeping-editor: Also print the working directory
Date: Fri, 6 Aug 2021 12:51:24 -0400 (EDT)

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

    with-editor-sleeping-editor: Also print the working directory
    
    When `git-commit' is invoked from a sub-directory, then it changes the
    working directory to the root of the working tree before invoking the
    editor.  Additionally it ask the editor to edit a relative path in
    most cases.  That path is relative to the top-level, so we need the
    sleeping editor to also print the name of that directory; or we would
    end up trying to edit e.g. "/path/to/repo/subdir/.git/COMMIT_EDITMSG"
    instead of "/path/to/repo/.git/COMMIT_EDITMSG".
    
    Actually, as of 2.19.0, `git-commit' no longer does this, it uses an
    absolute file-name now.  But programs might still do it and that is
    legitimate.  `$EDITOR' inherits the working directory from its parent
    process, so it normally isn't a problem if the file-name is relative.
    It only a problem here because `$EDITOR' in hour case forwards the
    edit request to a running `emacs' instance, which is not a child
    process and therefore does not inherit the working directory.
    
    Fixes #55.
---
 with-editor.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/with-editor.el b/with-editor.el
index b61104a..8afa487 100644
--- a/with-editor.el
+++ b/with-editor.el
@@ -173,7 +173,7 @@ please see 
https://github.com/magit/magit/wiki/Emacsclient.";))))
 
 (defcustom with-editor-sleeping-editor "\
 sh -c '\
-echo \"WITH-EDITOR: $$ OPEN $0\"; \
+echo \"WITH-EDITOR: $$ OPEN $0 IN $(pwd)\"; \
 sleep 604800 & sleep=$!; \
 trap \"kill $sleep; exit 0\" USR1; \
 trap \"kill $sleep; exit 1\" USR2; \
@@ -202,7 +202,7 @@ with \"bash\" (and install that), or you can use the older, 
less
 performant implementation:
 
   \"sh -c '\\
-  echo \\\"WITH-EDITOR: $$ OPEN $0\\\"; \\
+  echo \\\"WITH-EDITOR: $$ OPEN $0 in $(pwd)\\\"; \\
   trap \\\"exit 0\\\" USR1; \\
   trap \\\"exit 1\" USR2; \\
   while true; do sleep 1; done'\"
@@ -211,6 +211,7 @@ Note that this leads to a delay of up to a second.  The 
delay can
 be shortened by replacing \"sleep 1\" with \"sleep 0.01\", or if your
 implementation does not support floats, then by using `nanosleep'
 instead."
+  :package-version '(with-editor . "2.8.0")
   :group 'with-editor
   :type 'string)
 
@@ -552,14 +553,17 @@ which may or may not insert the text into the PROCESS' 
buffer."
 
 (defun with-editor-output-filter (string)
   (save-match-data
-    (if (string-match "^WITH-EDITOR: \\([0-9]+\\) OPEN \\(.+?\\)\r?$" string)
+    (if (string-match "^WITH-EDITOR: \
+\\([0-9]+\\) OPEN \\([^]+?\\)\
+\\(?: IN \\([^\r]+?\\)\\)?\r?$" string)
         (let ((pid  (match-string 1 string))
-              (file (match-string 2 string)))
-          (with-current-buffer
-              (find-file-noselect
-               (if (and (file-name-absolute-p file) default-directory)
-                   (concat (file-remote-p default-directory) file)
-                 (expand-file-name file)))
+              (file (match-string 2 string))
+              (dir  (match-string 3 string)))
+          (unless (file-name-absolute-p file)
+            (setq file (expand-file-name file dir)))
+          (when default-directory
+            (setq file (concat (file-remote-p default-directory) file)))
+          (with-current-buffer (find-file-noselect file)
             (with-editor-mode 1)
             (setq with-editor--pid pid)
             (run-hooks 'with-editor-filter-visit-hook)



reply via email to

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