并排镜像两个打开的缓冲区中的文件位置

2024-05-02

我试图在 emacs 中找到一个包/函数,它可以并排打开两个文件,使其位于同一行位置,镜像正在移动的缓冲区的移动。 这意味着,对于并排打开的两个缓冲区,在其中一个缓冲区中移动(向上/向下翻页、移动光标等)将在另一个缓冲区中进行相同的移动。

更具体地说,当打开缓冲区时(并且在激活此模式时),打开的缓冲区应该已经位于另一个缓冲区窗口中已打开的缓冲区的行位置。


你可以尝试scroll-all-mode。这将打开一帧的所有窗口的并行滚动。

Scrolling with the mouse and scroll bar do not work for me. But all scrolling with keys (such as Pg-Down, Pg-Down and cursor movements) works fine.

编辑: 您也可以尝试以下代码。它仅适用于具有两个窗口的框架,不计算迷你缓冲区。您必须首先打开文件并确保它们并排显示在两个窗口中。然后通过激活定义主窗口sync-window-mode为了它。确保两个窗口的换行均已关闭。

编辑:修复了一个问题(有时必须按两次按钮才能同步)。 解决方案:也挂钩window-scroll-functions. At post-command-hook正确的window-start位置未知,因为redisplay还没跑。未来的第一点window-start已知位于window-scroll-functions.

(defun sync-window (&optional display-start)
  "Synchronize point position other window in current frame.
Only works if there are exactly two windows in the active wrame not counting the minibuffer."
  (interactive)
  (when (= (count-windows 'noMiniBuf) 2)
    (let ((p (point))
      (start (or display-start (window-start)))
      (vscroll (window-vscroll)))
      (other-window 1)
      (goto-char (min (max p (point-min)) (point-max)))
      (set-window-start (selected-window) start)
      (set-window-vscroll (selected-window) vscroll)
      (other-window 1)
      )))

(define-minor-mode sync-window-mode
  "Synchronized view of two buffers in two side-by-side windows."
  :group 'windows
  :lighter " ⇕"
  (if sync-window-mode
      (progn
    (add-hook 'post-command-hook 'sync-window-wrapper 'append t)
    (add-to-list 'window-scroll-functions 'sync-window-wrapper)
    (sync-window))
    (remove-hook 'post-command-hook 'sync-window-wrapper t)
    (setq window-scroll-functions (remove 'sync-window-wrapper window-scroll-functions))
    ))

(defun sync-window-wrapper (&optional window display-start)
  "This wrapper makes sure that `sync-window' is fired from `post-command-hook'
only when the buffer of the active window is in `sync-window-mode'."
  (with-selected-window (or window (selected-window))
    (when sync-window-mode
      (sync-window display-start))))

(provide 'sync-window)

接下来是同步行而不是字符位置的版本。

如果您选择主缓冲区中的某些行,这也会标记从属缓冲区中的相应行。突出显示将保持永久状态,直到您在主缓冲区中选择另一个区域。它甚至在停用后仍然存在sync-window-mode在主缓冲区中。您可以通过以下方式获得突出显示效果

M-x sync-window-cleanup

在从属缓冲区中。

(defface sync-window-face ;; originally copied from font-lock-function-name-face
  '((((class color) (min-colors 88) (background light)) (:foreground "Yellow" :background "Blue1"))
    (((class color) (min-colors 88) (background dark)) (:foreground "Red" :background  "LightSkyBlue"))
    (((class color) (min-colors 16) (background light)) (:foreground "Blue" :background "Yellow"))
    (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue" :background "Yellow"))
    (((class color) (min-colors 8)) (:foreground "blue" :bold t))
    (t (:bold t)))
  "Face used to highlight regions in `sync-window-mode' slaves."
  :group 'sync-window)

(defvar sync-window-overlay nil
  "Overlay for current master region in `sync-window-mode' slaves.")
(make-variable-buffer-local 'sync-window-overlay)

(defun sync-window-cleanup ()
  "Clean up after `sync-window-mode'."
  (interactive)
  (if (overlayp sync-window-overlay)
      (progn
    (delete-overlay sync-window-overlay)
    (setq sync-window-overlay nil))
    (remove-overlays (point-min) (point-max) 'sync-window-slave t)))

(defvar sync-window-master-hook nil
  "Hooks to be run by `sync-window' in the master window ")

(defun sync-window (&optional display-start)
  "Synchronize point position other window in current frame.
Only works if there are exactly two windows in the active wrame not counting the minibuffer."
  (interactive)
  (when (= (count-windows 'noMiniBuf) 2)
    (let ((p (line-number-at-pos))
      (start (line-number-at-pos (or display-start (window-start))))
      (vscroll (window-vscroll))
      breg ereg)
      (when (use-region-p)
    (setq breg (line-number-at-pos (region-beginning))
          ereg  (line-number-at-pos (if (looking-back "\n") (1- (region-end)) (region-end)))))
      (run-hooks 'sync-window-master-hook)
      (other-window 1)
      (goto-char (point-min))
      (when breg
    (sync-window-cleanup)
    (overlay-put (setq sync-window-overlay (make-overlay (line-beginning-position breg) (line-end-position ereg))) 'face 'sync-window-face)
    (overlay-put sync-window-overlay 'sync-window-slave t))
      (setq start (line-beginning-position start))
      (forward-line (1- p))
      (set-window-start (selected-window) start)
      (set-window-vscroll (selected-window) vscroll)
      (other-window 1)
      (unless display-start
    (redisplay t))
      )))

(defvar sync-window-mode-hook nil
  "Hooks to be run at start of `sync-window-mode'.")

(define-minor-mode sync-window-mode
  "Synchronized view of two buffers in two side-by-side windows."
  :group 'windows
  :lighter " ⇕"
  (if sync-window-mode
      (progn
    (add-hook 'post-command-hook 'sync-window-wrapper 'append t)
    (add-to-list 'window-scroll-functions 'sync-window-wrapper)
    (run-hooks 'sync-window-mode-hook)
    (sync-window))
    (remove-hook 'post-command-hook 'sync-window-wrapper t)
    (setq window-scroll-functions (remove 'sync-window-wrapper window-scroll-functions))
    ))

(defun sync-window-wrapper (&optional window display-start)
  "This wrapper makes sure that `sync-window' is fired from `post-command-hook'
only when the buffer of the active window is in `sync-window-mode'."
  (with-selected-window (or window (selected-window))
    (when sync-window-mode
      (sync-window display-start))))

(provide 'sync-window)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

并排镜像两个打开的缓冲区中的文件位置 的相关文章

  • Emacs/Swank/Paredit for Clojure 的温和教程

    我要转向 Emacs 来工作Clojure http en wikipedia org wiki Clojure Lisp 为了能够执行以下操作 我需要在 Emacs 上设置哪些信息 自动匹配 生成相应的右括号 自动缩进 Lisp Cloj
  • Emacs-Lisp:如何将emacs-lisp程序打包为PC应用程序?

    只是想知道是否可以将 emacs 和 Lisp 程序打包和部署为 PC 应用程序 这样一旦下载并运行 setup exe 某种程度 用户就可以启动应用程序以使 emacs 运行特定的 Lisp 程序 就像应用程序已实现一样通过其他语言和平台
  • 让 Emacs ansiterm 和 Zsh 更好地发挥作用

    我一直在尝试在 emacs 会话中使用 Zsh 而无需 emacs 重新映射所有 Zsh 键 我发现 ansi term 对此非常有效 但是我仍然遇到一些问题 我输出了很多垃圾字符 我可以用以下方法修复它 Setup proper term
  • 配置jedi不自动完成?

    我在 emacs 中安装了 jedi mode 来进行 python 编辑 因为我发现C and C 对于跳转到定义并返回非常有用 然而 自动完成并不是我想要的 当我尝试在安装了 jedi 的情况下使用 emacs 时 它会不断尝试提供建议
  • Emacs:在缓冲区求值期间将参数传递给下级 Python shell

    最近我开始使用 Emacs 作为 Python IDE 它不太直观 我现在遇到的问题是当使用 C c C c 评估缓冲区时如何将命令行参数传递给下级 python shell 感谢帮助 这似乎并不容易实现 管理的劣质流程python el模
  • 为什么在 emacs-lisp 中的函数参数之前使用#'?

    我熟悉 Emacs Lisp 但不熟悉 Common 或任何其他 Lisp 一些 Lisp 程序员建议 例如emacs 的基本功能 https stackoverflow com questions 17076646 a basic fun
  • 如何在 emacs lua-mode 中配置缩进?

    完整的 emacs 新手在这里 我在 Ubuntu 上使用 emacs 23 1 1emacs 入门套件 https github com technomancy emacs starter kit 我主要在 lua 模式下工作 安装了pa
  • Emacs 行编号性能

    我试过了linum and nlinum 两者对于超过 100k 行的文件的性能都很糟糕 for x in 1 100000 do echo x done gt 100k txt emacs q 100k txt M x load libr
  • C# 开发人员有什么理由应该学习 Emacs/Vim 吗?

    我在一家纯粹的 Microsoft 商店担任 C 开发人员 最近 我开始在工作之余的空闲时间使用 Gas 和 Linux 自学汇编 我喜欢摆弄 Linux 尽管我对它还很陌生 我一直听说我应该学习 VIM 或 Emacs 但事实是 我绝对不
  • 在 Emacs 中,如何在迷你缓冲区中显示带有字体属性的消息?

    我想在迷你缓冲区中显示彩色文本字符串 但是当我使用 消息 函数时 文本属性被删除 对我有用 message s propertize foo face foreground red 你可能有 message propertize 它将属性化
  • Emacs 24.x 上的 IPython 支持

    我对 IPython 与 Emacs 的集成感到困惑 从 Emacs 24 开始 Emacs 附带了自己的python el 该文件是否支持 IPython 还是仅支持 Python 另外 维基百科 http emacswiki org e
  • Emacs + 流浪汉 + plink

    我正在尝试让 emacs trapmp 在 Windows XP 下运行 以便在 Amazon EC2 实例上通过 putty plink 工作 用于执行此操作的文档很少 我可以找到部分文档 但没有一个文档能够解决实现此功能所需的所有步骤
  • Mac OS High Sierra 下无法打开 pty

    我的问题的本质是 用户程序如何在 Mac OS High Sierra 上打开 pty 例如 dev ptyp0 设备名称的标准 open 似乎不起作用 尽管它的保护是 crw rw rw 上下文是在 Mac OS 下运行 Emacs 在
  • Emacs 启动时出现 24 错误

    我已经使用 emacs snapshot 一段时间了 但最近它崩溃了很多 所以我切换到 Emacs 24 但是一旦我安装并启动它 它就开始显示错误并且不会在我的 init el 中加载任何内容 当我在调试模式下运行它时 我得到了这个 Deb
  • 永久启用所有禁用的命令

    我想启用 Emacs 中所有禁用的命令 例如downcase region 也就是说 当调用时 它们不会要求用户确认 不幸的是 Emacs 手册的 48 3 11 禁用命令 部分没有提及启用all禁用命令永久 Emacs版本 24 0 95
  • 在 Slime 中复制/猛拉整个 Lisp 表单

    有没有办法在 Slime Emacs 中复制 猛拉整个表单 例如 如果我有以下功能 myfunc lst myotherfunc lst 我想复制 复制 myotherfunc lst 当我的光标位于该表单的左括号或右括号时 在 Slime
  • Emacs 是否具有单词和行补全功能(如 Vim 的插入模式补全功能)?

    Vim 完成单词和行CTRL X P and CTRL L 有一个名为 Company mode 的 Emacs 插件 但该插件会干扰 Emacs 中的许多内容并导致冲突 与全局 linum 和 yasnippets 我知道我可以在 Ema
  • 我可以在 Emacs 的 shell 模式下使用 PowerShell 吗?

    我可以在 emacs 的 shell 模式下使用 powershell 作为 shell 吗 How 请参阅 Jeffrey Snover 的博客文章在 Emacs 内运行的 PowerShell http blogs msdn com p
  • 使用 slime 时如何跳转到 emacs 中的函数定义?

    我已经使用安装了史莱姆https github com thephoeron slime pack https github com thephoeron slime pack并想进一步探索 common lisp 如何访问 emacs 中
  • 更改 Common Lisp REPL 中文本的颜色

    我想控制 Common Lisp 中显示的文本的颜色 像这样的伪代码 print color red hello blue world 有什么办法可以做到这一点吗 我使用 SBCL 我的 repl 位于 emacs 内 谢谢 您可以使用AN

随机推荐

  • 杰克逊:引用同一个对象

    在某些情况下 主体 例如 JSON 主体 中序列化或非序列化的数据包含对同一对象的引用 例如 包含球员列表以及由这些球员组成的球队列表的 JSON 正文 players name Player 1 name Player 2 name Pl
  • 在Android中获取Fragment中的应用程序上下文?

    我已通过在一个活动中使用应用程序上下文将一些数据存储到全局类中 稍后我必须在片段中检索这些值 我已经做了类似的事情来存储在全局类中 AndroidGlobalClass AGC AndroidGlobalClass getApplicati
  • 如何转换温度传感器得到的值?

    我在ST工作Temperature sensor hts221 我用I2C与传感器的命令通信 我从文档中看到类似以下文字 enter code here Temperature data are expressed as TEMP OUT
  • WPF 向我的 GUI 添加时钟

    简单请求 我希望能够在 WPF 应用程序窗口中显示当前时间 有免费的控件吗 只需要显示时间 没有别的 您可以有一个标签或文本块 并将其内容绑定到 System DateTime Now
  • Hibernate 验证器:违规消息语言

    我有一个测试类 我正在测试一个域模型 该模型用例如注释 NotNull 在我的测试课中 我首先得到验证器 private static Validator validator BeforeClass public static void s
  • Ember.js 动态子视图

    我无法让 ember 渲染动态子视图 似乎一旦渲染了子视图 绑定就会丢失 这是一个jsfiddle http jsfiddle net zaius XYzfa http jsfiddle net zaius XYzfa 当您在两个编辑器页面
  • CSS:悬停在多个 div 上时显示样式

    我有 2 个不同尺寸的 div 一个放在另一个上面 所以有一个共同的交叉区域 这两个 div 都有 CSS hover 规则集 如果我将鼠标悬停在每个 div 上 则规则适用 但是 如果我移过交叉区域 则只会激活顶部 div 悬停 当鼠标悬
  • 如何找到给定数组的所有可能的子集?

    我想在 C 或 C 中提取数组的所有可能子集 然后计算所有子集数组各自元素的总和 以检查其中有多少等于给定数字 我正在寻找的是算法 我确实理解这里的逻辑 但我现在还无法实现这一逻辑 考虑一组S of N元素 以及给定的子集 每个元素要么属于
  • 使用 pymongo 查询空字段

    我想使用 python 查询 mongo 中的空字段 但是它很难处理单词 null 或 false 它要么给我错误 它们在 python 中未定义 要么在 mongo 中搜索字符串 null 和 false 这两种情况我都不希望发生 col
  • Cloudflare Worker 缓存 API 出现问题

    我现在花了无数的时间尝试让缓存 API 来缓存一个简单的请求 我让它在中间工作过一次 但忘记向缓存键添加一些内容 现在它不再工作了 不用说 cache put 没有指定请求是否实际被缓存的返回值并不完全有帮助 我只能进行反复试验 有人可以给
  • 如何解决警告“没有明确的所有权”

    我有一种方法 它采用间接指针作为参数 然后 如果出现错误 将其设置为错误对象 我正在尝试打开尽可能多的警告 但其中之一 Implicit ownership types on out parameters 在此方法中生成警告 id doWi
  • asp.net 3.5 是否支持单个页面上的多个表单?

    我只是想确认这是否属实 我记得在某处读到现在这是可能的 但经过一个小时的谷歌搜索后我找不到任何明确的证据 在 ASP NET WebForms 中 您不能使用多个表单 因为它使用单个表单模型 在 ASP NET MVC 中您可以
  • 如何将2个匹配查询加入到elasticsearch的查询中?

    我想查询以下数据user id is 1 and name is John 写一个常用的SQL很容易 select from t where user id 1 and name John 但对我来说进行elasticsearch的查询并不
  • 从 Azure 流分析将数据插入 Azure SQL 数据库表时出现“OutputDataConversionError.TypeConversionError”

    我正在尝试学习 Azure IoT 我正在尝试将 MQTT 消息发送到 IoT 中心 在 IoT 中心 我使用流分析将数据输出到 SQL 数据库中 但目前在流分析输出中 我遇到此错误 9 12 30 AM 源 OUTPUTSQL 在处理时间
  • 如何设置按钮的大小?

    我将按钮放在带有 GridLayout 的 JPane 中 然后我用 BoxLayout Y AXIS 将 JPanel 放入另一个 JPanel 中 我希望 GridLayout 中的按钮是方形的 我使用 tmp setSize 30 3
  • 将列表视图项转换为单个位图图像

    参考这个主题 Android 获取所有 ListView 项目的屏幕截图 https stackoverflow com questions 12742343 android get screenshot of all listview i
  • WCF 复杂 JSON 输入错误(无法通过 QueryStringConverter 转换)

    我在将复杂 JSON 作为 WCF 服务中的参数工作时遇到问题 在 Visual Studio 2008 SP1 中使用 Microsoft Net 3 5 SP1 签订以下合同 ServiceContract public interfa
  • 带有 numberOfLines 和 lineBreakMode 的 UILabel

    我正在开发一个必须同时支持 iOS6 和 iOS7 的项目 我的问题是它在不同的系统上工作不同 我试图创建行数等于 2 的 UILabel 但是当我将其换行模式设置为 NSLineBreakByTruncatingTail 时 它的工作方式
  • 实时跟踪每分钟/小时/天的前 100 个 Twitter 单词

    我最近遇到这样一个面试问题 Given a continuous twitter feed design an algorithm to return the 100 most frequent words used at this min
  • 并排镜像两个打开的缓冲区中的文件位置

    我试图在 emacs 中找到一个包 函数 它可以并排打开两个文件 使其位于同一行位置 镜像正在移动的缓冲区的移动 这意味着 对于并排打开的两个缓冲区 在其中一个缓冲区中移动 向上 向下翻页 移动光标等 将在另一个缓冲区中进行相同的移动 更具