说我打开两个文件emacs -nw ./first-file ./second-file
。左缓冲区为second-file
,右缓冲区为first-file
。很多人已经习惯了它,我可以看到该参数,但是对我来说,它并不直观,因为实际命令中的first-file
位于second-file
的左侧。我知道以后会切换它们,但是我想知道.emacs中是否有一行可以自动执行此操作。
使用GNU Emacs 25.3.2
答案 0 :(得分:0)
用法示例:/path/to/emacs -nw --eval="(my-one-two \"foo\" \"bar\")"
(defun my-one-two (file-one file-two)
"Display FILE-ONE to the left and FILE-TWO to the right."
(let ((buffer-one (find-file-noselect file-one))
(buffer-two (find-file-noselect file-two)))
(delete-other-windows)
(set-window-buffer (selected-window) buffer-one)
(my-display-buffer buffer-two nil 'right)))
(defun my-display-buffer (buffer-or-name alist direction &optional size pixelwise)
"BUFFER: The buffer that will be displayed.
ALIST: See the doc-string of `display-buffer' for more information.
DIRECTION: Must use one of these symbols: 'left 'right 'below 'above
SIZE: See the doc-string for `split-window'.
PIXELWISE: See the doc-string for `split-window'.
There are three possibilities:
- (1) If a window on the frame already displays the target buffer,
then just reuse the same window.
- (2) If there is already a window in the specified direction in relation
to the selected window, then display the target buffer in said window.
- (3) If there is no window in the specified direction, then create one
in that direction and display the target buffer in said window."
(let* ((buffer
(if (bufferp buffer-or-name)
buffer-or-name
(get-buffer buffer-or-name)))
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction direction))
(t
(split-window (selected-window) size direction pixelwise)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
window))
答案 1 :(得分:0)
假设您正在某种Linux外壳上运行,我看到的最简单的方法是使用别名:
alias myE="emacs -nw $2 $1"
要立即运行emacs,请执行:myE file1 file2
,它会执行emacs -nw file2 file1
。
要坚持这一点,请将alias命令放入您的~/.bashrc
。