假设我打开两个文件emacs -nw ./first-file ./second-file。左边的缓冲区是second-file,右边的缓冲区是first-file。很多人已经习惯了它,我可以看到它的论点,但对我来说,这并不直观,因为在实际的命令中,first-file位于second-file的左侧。我知道之后我会切换它们,但我想知道在.emacs中是否有一行代码可以自动完成这一操作。
使用GNU Emacs 25.3.2
发布于 2018-08-07 05:29:53
示例用法:/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))发布于 2018-08-14 05:37:32
假设您在某种linux shell上运行,我认为最简单的方法是使用别名:
alias myE="emacs -nw $2 $1"现在要运行emacs -nw file2 file1,只需执行myE file1 file2,它就会执行emacs。
为了持久化这种情况,将别名命令放入~/.bashrc中。
https://stackoverflow.com/questions/51714735
复制相似问题