首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在emacs中以“相反”的顺序打开两个文件?

在emacs中以“相反”的顺序打开两个文件?
EN

Stack Overflow用户
提问于 2018-08-07 03:51:54
回答 2查看 95关注 0票数 0

假设我打开两个文件emacs -nw ./first-file ./second-file。左边的缓冲区是second-file,右边的缓冲区是first-file。很多人已经习惯了它,我可以看到它的论点,但对我来说,这并不直观,因为在实际的命令中,first-file位于second-file的左侧。我知道之后我会切换它们,但我想知道在.emacs中是否有一行代码可以自动完成这一操作。

使用GNU Emacs 25.3.2

EN

Stack Overflow用户

发布于 2018-08-07 05:29:53

示例用法:/path/to/emacs -nw --eval="(my-one-two \"foo\" \"bar\")"

代码语言:javascript
复制
(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))
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51714735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档