【问题标题】:In split window emacs, how to search the "other buffer first line" for ":" then shift the border of the original buffer to that point在拆分窗口emacs中,如何在“其他缓冲区第一行”中搜索“:”然后将原始缓冲区的边框移动到该点
【发布时间】:2013-11-27 22:20:27
【问题描述】:

我在monky.el 包中使用了blame-mercurial。 在拆分窗口中,当激活责备时,结果会出现在另一个窗口中,其中包含有关行更改的信息(作者/变更集/日期:)。 我想要一个搜索“结果”缓冲区的第一行的命令,到达标记“:”所在的位置并将原始缓冲区的边界向上移动到该点。

Basically, if the borders of both windows are:
| ......                        | ......              |
Before executing the command:
|author 4543 11-27-2013: int x; | int x;              |
After executing the command:
|author 4543 11-27-2013:| int x;                      |

这样做的原因是我想保留数据类型/函数的颜色...等,同时查看谁最后更改了这些源文件行。

在责备结果文件中,当行以作者变更集日期进行时。他们失去了他们的色彩。 所以我想将责任缓冲区中每一行的信息与原始字体文件“并排”使用。

我也不能使用固定的窗口边框移位值,因为根据每个文件的作者姓名长度,“:”的位置会相应改变。

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    我修改了最新版本 "Mirroring location in file in two opened buffers side by side" 这样下面的代码才有意义。如果您运行下面的代码,然后为mercury-blame 缓冲区打开sync-window-mode,那么isearch 将产生预期的效果。

    (defun mercury-blame-resize ()
      "Resize mercury blame window to blame string at point only."
      (interactive) ;; for debugging
      (window-resize (selected-window)
             (- (save-excursion
                  (beginning-of-line)
                  (skip-chars-forward "^:\n"))
                (window-width) -1)
             'horizontal 'ignore-fixed-size))
    
    (add-hook 'sync-window-master-hook 'mercury-blame-resize)
    
    (add-hook 'sync-window-mode-hook '(lambda ()
                        (setq-local isearch-update-post-hook #'(lambda () (set-window-hscroll (selected-window) 0)))))
    

    emacs 23 的版本:

    (defvar mercury-blame-resize-min 5)
    
    (defun mercury-blame-resize ()
      "Resize mercury blame window to blame string at point only."
      (interactive) ;; for debugging
      (save-excursion
        (beginning-of-line)
        (let ((n (skip-chars-forward "^:\n")))
          (when (looking-at ":")
        (condition-case err
            (enlarge-window (- (max mercury-blame-resize-min n)
                       (window-width) -1)
                    'horizontal)
          (error))))))
    
    
    (add-hook 'sync-window-master-hook 'mercury-blame-resize)
    
    (add-hook 'sync-window-mode-hook '(lambda ()
                        (set (make-local-variable 'isearch-update-post-hook) #'(lambda () (set-window-hscroll (selected-window) 0)))))
    

    测试助手(不含汞):

    (loop for i from 1 upto 100 do
          (loop for j from 0 upto (random 20) do
            (insert (+ 32 (random 20))))
          (insert ":\n"))
    

    编辑:在 emacs 23 版本中:仅当当前行有“:”时才重新调整 mercurity blame 缓冲区的大小。

    【讨论】:

    • hmmm...我试过了,但我不断收到“符号函数定义 setq-local 无效”
    • 你不应该遇到window-resize 的问题,因为你只使用标有Version for emacs 23: 的代码。在sync-window-mode 的内容之外执行此代码。然后为mercury-blame-缓冲区激活symc-window-mode不是为另一个!)。然后isearchmerury-blame 缓冲区中想要的名称。好的,这里的问题可能是您实际上想要在原始源代码缓冲区中搜索某些内容。如果是这样,请告诉我。要在 merury-blame 缓冲区中手动使用 M-x mercury-blame-resize,您无需更改任何内容。
    • 小心!它还不是万无一失的。这是由于我的时间预算有限。你总是可以通过M-x sync-window-mode关闭怪物来逃脱...
    • 现在,在 emacs 23 版本中,当当前行没有“:”时,会跳过重新调整大小。我目前正在从事一个大型且耗时的项目。因此,酷的东西必须等待。但听起来你确实为错误的窗口激活了同步窗口模式。如果您在 mecury-blame 窗口中激活它,应该可以搜索名称。
    • 我牢记这一点。我只是很忙。我打算在 emacswiki.org 上放一个包。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    相关资源
    最近更新 更多