AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Emacs flag to open in terminal3/11/2023 ![]() ![]() current buffer is the shell buffer (`in-shell'). toggle shell window restore windows when called twice in a row, or the With prefix-arg close shell, restore windows. (not (eq shell-frame (selected-frame))))))) (and inject-cd (not (bufferp shell-buf))) (popup-frame (or (string= display 'frame) (in-shell (eq (current-buffer) shell-buf)) (if shell-window (window-frame shell-window))) (if shell-buf (get-buffer-window shell-buf t))) (shell-window non-nil when currently displayed (let* ((shell-buf (get-buffer "*shell*")) To the working directory of the buffer from which you toggled the shell." When DISPLAY is 'vertical splits the shell as vertical window when 'frame usesĪ dedicated frame (default: single window). "Toggles between current buffers and a system shell buffer. (defun -toggle-shell (&optional display inject-cd) (message "%s: buffer not available" bufnam)))))) (if (get-buffer bufnam) (switch-to-buffer bufnam t) (buffer-name -toggle-shell-last-buf) -toggle-shell-last-buf))) (let ((bufnam (if (bufferp -toggle-shell-last-buf) (set-window-configuration -toggle-shell-last-window-conf)) (progn (raise-frame -toggle-shell-last-frame) (defun -toggle-shell-restore-last-conf () toggle-shell-last-window-conf (current-window-configuration))) toggle-shell-last-frame (selected-frame) (setq -toggle-shell-last-buf (current-buffer) (window-configuration-p -toggle-shell-last-window-conf)) (defvar -toggle-shell-last-frame nil "The frame that was selected when opening a shell buffer.") (defvar -toggle-shell-last-buf nil "The last buffer object in case there's no last window configuration.") emacs: (defvar -toggle-shell-last-window-conf nil "The last window configuration.") It can also put the shell into a dedicated frame, and inject a pushd to the current buffer directory. It toggles between the current frame or window configuration and a system shell buffer. I had exactly the same problem some years ago, and found nothing that satisfied me so I wrote my own "toggle shell" function. (defadvice ansi-term (after ansi-term-after-advice (org)) (define-key term-raw-map (kbd "C-t") 'shell-pop))) If you use "ansi-term" and want to use C-t (shell-pop-set-window-height 60) Give shell buffer 60% of window (shell-pop-set-internal-mode "eshell") Or "ansi-term" if you prefer Here's and example of my shell-pop configuration, I use the key C-t to pop up an eshell: (require 'shell-pop) shell-pop lets you assign a key to opening and closing a specific shell buffer window, if you've used drop-down terminals like tilda you know how incredibly handy this can be: shell-pop.el, a great tool for quick terminal access.multi-term.el makes managing terminals a bit easier.In your case you could dedicate one screen to terminals. elscreen.el is a life saver, if you have a complicated window layout like gdb or have simply become overwhelmed with clutter you just open a new screen.I use many methods for incorporating my terminal life into Emacs: If buffer *host05* already existed, it would simply switch me to it. If I didn't already have a buffer named *host05*, it would start a new terminal emulator buffer, rename it to *host05*, and ssh me into. Then I bound this command to (say) s-h (super H), enabling me to just type M-5 s-h. (get-buffer-process (rename-buffer buffer-name)) ![]() I wrote a little function like this one to make it easier to manage them all: (defun ssh-to-host (num) In the case of M-x shell, a prefix argument will cause you to be prompted for the name of the new shell buffer, as offby1 noted.Ī few years ago I had a job where I had to regularly log in to various production servers named "", "", etc. Just use M-x rename-buffer to change the name of an existing *term* or *shell* buffer, and the next time you do M-x term or M-x shell, a brand new buffer will be created. You can have as many terminals and shells open at once as you want. ![]()
0 Comments
Read More
Leave a Reply. |