magit / with-editor

Use the Emacsclient as the $EDITOR of child processes
http://magit.vc/manual/with-editor
GNU General Public License v3.0
188 stars 44 forks source link

with-editor-export-editor affecting find-dired #6

Closed xenodium closed 8 years ago

xenodium commented 8 years ago

M-x find-dired no longer works when using (add-hook 'shell-mode-hook 'with-editor-export-editor):

Debugger entered--Lisp error: (wrong-type-argument processp nil) set-process-filter(nil find-dired-filter) find-dired("some/path" "") call-interactively(find-dired record nil) command-execute(find-dired record) helm-M-x(nil "find-dired") call-interactively(helm-M-x nil nil) command-execute(helm-M-x)

Don't have a solution :( Currently working around it with:

(defun ar/use-emacs-for-shell-editor ()
  (unless (string-match-p "Find" (buffer-name))
    (with-editor-export-editor)))

(use-package with-editor :ensure t
  :config
  (add-hook 'shell-mode-hook 'ar/use-emacs-for-shell-editor))

Other than that, with-editor is working great in shell-mode. Thank you!

tarsius commented 8 years ago

I can reproduce this. Some more details:

Debugger entered--Lisp error: (wrong-type-argument processp nil)
  set-process-filter(nil find-dired-filter)
  (let ((proc (get-buffer-process (current-buffer)))) (set-process-filter proc (function find-dired-filter)) (set-process-sentinel proc (function find-dired-sentinel)) (move-marker (process-mark proc) (point) (current-buffer)))
  (let ((dired-buffers dired-buffers)) (setq dir (file-name-as-directory (expand-file-name dir))) (or (file-directory-p dir) (error "find-dired needs a directory: %s" dir)) (switch-to-buffer (get-buffer-create "*Find*")) (let ((find (get-buffer-process (current-buffer)))) (if find (progn (if (or (not (eq ... ...)) (yes-or-no-p (format-message "A `find' process is running; kill it? "))) (condition-case nil (progn (interrupt-process find) (sit-for 1) (delete-process find)) (error nil)) (error "Cannot have two processes in `%s' at once" (buffer-name)))))) (widen) (kill-all-local-variables) (setq buffer-read-only nil) (erase-buffer) (setq default-directory dir find-args args args (concat find-program " . " (if (string= args "") "" (concat (shell-quote-argument "(") " " args " " (shell-quote-argument ")") " ")) (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|+\\)\\'" (car find-ls-option)) (format "%s %s %s" (match-string 1 (car find-ls-option)) (shell-quote-argument "{}") find-exec-terminator) (car find-ls-option)))) (shell-command (concat args "&") (current-buffer)) (dired-mode dir (cdr find-ls-option)) (let ((map (make-sparse-keymap))) (set-keymap-parent map (current-local-map)) (define-key map "" (quote kill-find)) (use-local-map map)) (make-local-variable (quote dired-sort-inhibit)) (setq dired-sort-inhibit t) (set (make-local-variable (quote revert-buffer-function)) (list (quote lambda) (quote (ignore-auto noconfirm)) (list (quote find-dired) dir find-args))) (if (fboundp (quote dired-simple-subdir-alist)) (dired-simple-subdir-alist) (set (make-local-variable (quote dired-subdir-alist)) (list (cons default-directory (point-min-marker))))) (set (make-local-variable (quote dired-subdir-switches)) find-ls-subdir-switches) (setq buffer-read-only nil) (insert "  " dir ":\n") (let ((point (point))) (insert "  " args "\n") (dired-insert-set-properties point (point))) (setq buffer-read-only t) (let ((proc (get-buffer-process (current-buffer)))) (set-process-filter proc (function find-dired-filter)) (set-process-sentinel proc (function find-dired-sentinel)) (move-marker (process-mark proc) (point) (current-buffer))) (setq mode-line-process (quote (":%s"))))
  find-dired("/home/jonas/.emacs.d/lib/org/lisp/" "-name foo")
...

So it appears our hook function somehow affects what buffer is current.

tarsius commented 8 years ago

This might be a regression similar to #8 due to the mode hook now being executed at a different time.

tarsius commented 8 years ago

Fixes. Thanks for reporting.

xenodium commented 8 years ago

Thank you =)

destroyhimmyrobots commented 7 years ago

Should (shell-mode-hook (remove 'with-editor-export-editor shell-mode-hook)) also remove with-editor-export-git-editor and with-editor-export-hg-editor? I am encountering the same error during a find-name-dired in Emacs 24.5:

(wrong-type-argument processp nil)
  process-filter(nil)
  with-editor-export-editor("GIT_EDITOR")
  with-editor-export-git-editor()
  run-hooks(change-major-mode-after-body-hook comint-mode-hook shell-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook comint-mode-hook shell-mode-hook))
  run-mode-hooks(shell-mode-hook)
  shell-mode()
  shell-command--shell-command-with-editor-mode(...)

with-editor has these hooks registered via init.el:

              (dolist (h '(shell-mode-hook term-exec-hook eshell-mode-hook))
                (add-hook h #'with-editor-export-editor)
                (add-hook h #'with-editor-export-git-editor)
                (add-hook h #'with-editor-export-hg-editor))

(Also, it would be nice if these three were autoloads to declutter the use-package declaration for with-editor.)