Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell-pop-default-directory changes buffer default-directory #64

Open
dwrz opened this issue Aug 11, 2019 · 4 comments
Open

shell-pop-default-directory changes buffer default-directory #64

dwrz opened this issue Aug 11, 2019 · 4 comments

Comments

@dwrz
Copy link

dwrz commented Aug 11, 2019

When I invoke shell-pop, it changes the default-directory of the current buffer to shell-pop-default-directory.

Is it possible to just have shell-pop-default-directory apply to the pop up shell, and not to the previously selected buffer?

This is with Emacs 26.2 on Linux 5.2.5, x86_64.

Following is my config:

(use-package shell-pop
  :bind (("C-s-t" . shell-pop)
         ("C-x t" . shell-pop))
  :ensure t
  :custom
  (shell-pop-shell-type
   '("eshell" "*eshell*" (lambda nil (interactive) (eshell))))
  :config
  (setq shell-pop-window-size 30)
  (setq shell-pop-full-span nil)
  (setq shell-pop-default-directory "~")
  (setq shell-pop-universal-key "C-s-t")
  (setq shell-pop-window-position "bottom")
  (setq shell-pop-in-after-hook 'end-of-buffer))
@dwrz dwrz changed the title shell-pop default directory changes buffer default directory shell-pop-default-directory changes buffer default directory Aug 11, 2019
@dwrz dwrz changed the title shell-pop-default-directory changes buffer default directory shell-pop-default-directory changes buffer default-directory Aug 11, 2019
@prasoon2211
Copy link

Sorry to revive the dead thread. @dwrz did you find a fix for this perhaps?

@dwrz
Copy link
Author

dwrz commented Apr 26, 2020

@prasoon2211 Sorry, I no longer use shell-pop. I vaguely recall this issue wasn't just due to shell-pop, but I'm not very sure.

shackra added a commit to shackra/emacs that referenced this issue Jun 3, 2020
@SirVolta
Copy link

SirVolta commented Jan 6, 2021

@prasoon2211 I've had this issue too. It seems to be fixable by advising #'shell-pop--cd-to-cwd-eshell to only run in eshell buffers and only auto-cd when necessary. I've also had to work around another, possibly related, bug involving the buffer directory not being detected properly. Taking the directory part of buffer-file-name seems to work much better then default-directory.
With these workarounds shell-pop works well for me using Emacs 27.1 on Debian.

(defun sv/fixed-shell-pop--cd-to-cwd-eshell (cwd)
  (if (string= major-mode "eshell-mode")
      t
    (message "Trying to set eshell CWD (%s) outside of eshell!" cwd)
    nil))

(advice-add 'shell-pop--cd-to-cwd-eshell :before-while #'sv/fixed-shell-pop--cd-to-cwd-eshell)

(defun sv/shell-pop (arg)
  (interactive "P")
  (let ((default-directory
          (or (file-name-directory (or (buffer-file-name) "")) default-directory))
        (shell-pop-autocd-to-working-dir (stringp (buffer-file-name))))
    (shell-pop arg)))

(define-key xah-fly-leader-key-map (kbd "z") #'sv/shell-pop)

config:

(setq shell-pop-default-directory (expand-file-name "~")
      shell-pop-shell-type  '("eshell" "*eshell*" (lambda () (eshell)))
      shell-pop-universal-key nil
      shell-pop-window-size 30
      shell-pop-full-span t
      shell-pop-autocd-to-working-dir t
      shell-pop-window-position "bottom")

@gabberdancecat
Copy link

gabberdancecat commented Jul 5, 2023

I found the issue to be problematic when running shell-pop while in an org file with code blocks. If a code block tangles to a relative path, for example #+begin_src :tangle ./setup, and it intends to tangle to /home/user/code/project1/setup, after running shell-pop, it would try to tangle to /home/user/setup instead, as the default-directory would've changed from /home/user/code/project1/ to /home/user/.

I haven't tried @SirVolta's solution yet, but i might just use popper.el instead, which can turn any buffer into a pop-up window, so i'll use that and script together a makeshift pop-up terminal instead.

Update: the package multi-term provides a command to create a dedicated pop-up terminal window (multi-term-dedicated-toggle), just like shell-pop does. There's another called multi-vterm, which only supports vterm (I'm assuming this had to be created because of compatibility issues between vterm and multi-term). I've tried multi-vterm and it works great, but multi-term, the original, doesn't work as well as shell-pop, nor does it support eshell...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants