0

My specific goal is setting 'vc-mode from the $PROMPT1 snippet so that the mode line will show useful VC info in shell-mode.

I can use emacsclient -e '(setq vc-mode "foo")' but that's not quite enough since 'vc-mode needs to be a buffer local variable, and so I will first need to pass the name of the shell-mode buffer into bash somehow.

Is there a known pattern for doing this kind of thing?

  • You could write a shell function asking Emacs which buffer corresponds to the process with pid $$. – politza Jun 1 '17 at 19:04
  • 1
    You don't need to pass the name of the buffer to bash: emacsclient -e "(with-current-buffer (process-buffer (cl-find $$ (process-list) :test (lambda (pid pr) (eq pid (process-id pr))))) (setq vc-mode \"foo\"))" – Tobias Jun 1 '17 at 21:49
  • One comment more related to the question itself: The biggest difficulties with running shell commands in a comint-buffer from elisp are related to the asynchronous execution of the shell. When executing commands one needs to take care of pending output. But, setting environment-variables of the shell does not require capturing of the output. So (comint-send-string (get-buffer-process (current-buffer)) (concat "EMACS_BUFFER=" (buffer-name))) should essentially work. One has to advice rename-buffer such that EMACS_BUFFER is kept current. Alternatively set EMACS_BUFFER before use. – Tobias Jun 4 '17 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.