Emacs -- 修改 `fill-column-indicator.el` 以在空白处显示

2024-05-18

我正在寻求一些帮助来修改fill-column-indicator.el由 Alp Aker 设计,以便垂直线在空白处可见(无论空白模式是否处于活动状态)。

以下是该库的 Github 存储库的链接:

https://github.com/alpaker/Fill-Column-Indicator/blob/master/fill-column-indicator.el https://github.com/alpaker/Fill-Column-Indicator/blob/master/fill-column-indicator.el

目前,垂直线在空白处不可见。

下面的代码,当与fill-column-indicator.el,创建一条跟踪当前光标列位置的垂直线。我已经检查过的代码fill-column-indicator.el但是,我无法找到在存在空格时阻止出现垂直线的代码部分。

(defun fci-mode-current-column ()
  (setq fill-column (current-column))
  (setq cursor-type '(hbar . 2))
  (fci-mode t))

(add-hook 'post-command-hook 'fci-mode-current-column)

Example
(source: lawlist.com http://www.lawlist.com/images/fill_column_indicator.png)


2014 年 5 月 1 日:创建了第一份工作草案。

2014 年 5 月 2 日:修改了多个 fci 模式功能,并包含了先前草案的部分内容。

2014 年 5 月 3 日:修复了选项卡右侧列的突出显示问题。合并了准后命令挂钩,以精确控制何时使用垂直标尺重绘缓冲区,并删除了以前由 fci 模式使用的挂钩。

2014 年 5 月 4 日:添加了部分兼容性whitespace-mode使用设置(setq whitespace-style '(face space-mark tab-mark newline-mark) ). The 前景 for tab-mark and newline-mark被突出显示。但是,那背景未突出显示,因为每个标记跨越多于一列(但宽度point只等于一)。


;;;;;;;;;;;;;;;;;;;;;;;;; LAWLIST MODIFICATIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://stackoverflow.com/a/23418459/2112489
;;
;; In order to use these modifications to enable vertical highlighting of the
;; current column, the library `fill-column-indicator.el` by Alp Aker is needed.
;;   https://github.com/alpaker/Fill-Column-Indicator
;; The code set forth hereinbelow is intended to replace functions or variables
;; within the aforementioned library that contain the same names.  There are
;; also a few new functions and variables below.

(define-minor-mode fci-mode
  :group 'fci-mode
  :lighter " fci"
  :global nil
  :init-value nil
  (if fci-mode
      ;; Enabling.
      (condition-case error
          (progn
            (fci-check-user-options)
            (fci-process-display-table)
            (fci-set-local-vars)
            (fci-get-frame-dimens)
            ;; (dolist (hook fci-hook-assignments)
            ;;   (add-hook (car hook) (nth 1 hook) nil (nth 2 hook)))
            (setq fci-column (current-column))
            (setq fci-tab-width tab-width)
            (setq fci-limit
              (if fci-newline
                (1+ (- fci-column (length fci-saved-eol)))
                fci-column))
            (fci-make-overlay-strings)
            (fci-update-all-windows t)
            (if linum-mode
            (linum-update-current)))
        (error
         (fci-mode 0)
         (signal (car error) (cdr error))))
    ;; Disabling.
    (fci-restore-display-table)
    (fci-restore-local-vars)
    (dolist (hook fci-hook-assignments)
      (remove-hook (car hook) (nth 1 hook) (nth 2 hook)))
    (fci-delete-overlays-buffer)
    (dolist (var fci-internal-vars)
      (set var nil))))

(defvar my-column-overlay nil
  "The overlays used in this buffer.")
(make-variable-buffer-local 'my-column-overlay)

(defvar my-cursor-point nil
"Point used to prevent the formation of a cursor overlay.
It must be set within the function `fci-redraw-region`.")
(make-variable-buffer-local 'my-cursor-point)

(defun fci-put-overlays-region (start end)
"Place overlays displaying the fill-column rule between START and END."
  (let* (my-last-column fci-overlay my-overlay-beg my-overlay-end)
    (setq cursor-type 'hollow)
    (goto-char end)
    (while (re-search-backward "\n" start t)
      (setq my-last-column (current-column))
      (setq fci-overlay (make-overlay (match-beginning 0) (match-beginning 0)))
      (overlay-put fci-overlay 'fci t)
      (cond
       ((< my-last-column fci-limit)
        (overlay-put fci-overlay 'after-string fci-pre-limit-string))
       ((> my-last-column fci-limit)
        (overlay-put fci-overlay 'after-string fci-post-limit-string))
       (t
        (overlay-put fci-overlay 'after-string fci-at-limit-string)))
      (setq my-overlay-beg (progn (move-to-column fci-column) (point)))
      (setq my-overlay-end (+ 1 my-overlay-beg))
      (setq my-column-overlay (make-overlay my-overlay-beg my-overlay-end ))
      (cond
        ;; text, excluding tabs
        ((and
            (not (save-excursion (move-to-column (+ 1 fci-column))
              (eq (preceding-char) 9)))
            (not (eq my-cursor-point my-overlay-beg))
            (< fci-column my-last-column))
          (overlay-put my-column-overlay 'face
            '(:background "DarkRed") ) )
        ;; tab with text to the right
        ((and
            (not (bobp)) ;; do NOT try to go beyond the beginning of the buffer
            (not (not (save-excursion (move-to-column fci-column)
              (backward-char 1) (eq (char-after (point)) 9))))
            (not (save-excursion (move-to-column (+ 1 fci-column))
              (eq (char-after (point)) 9)))
            (save-excursion (move-to-column fci-column)
              (eq (char-after (point)) 9))
            (not (eq my-cursor-point my-overlay-beg))
            (< fci-column my-last-column))
          (overlay-put my-column-overlay 'face
            '(:foreground "Red" :weight bold) ) )
        ;; tab with text to the left
        ((and
            (not (bobp)) ;; do NOT try to go beyond the beginning of the buffer
            (not (save-excursion (move-to-column fci-column)
              (backward-char 1) (eq (char-after (point)) 9)))
            (save-excursion (move-to-column fci-column)
              (eq (char-after (point)) 9))
            (not (eq my-cursor-point my-overlay-beg))
            (< fci-column my-last-column))
          (overlay-put my-column-overlay 'face
            '(:foreground "Red" :weight bold) ) )
        ;; tab sandwiched between a tab on each side
        ((and
            (not (bobp)) ;; do NOT try to go beyond the beginning of the buffer
            (save-excursion (move-to-column fci-column)
              (eq (char-after (point)) 9))
            (not (eq
              (save-excursion (move-to-column fci-column)
                (re-search-backward "\t" (point-at-bol) t) (point))
              (save-excursion (move-to-column (+ fci-column 1))
                (re-search-backward "\t" (point-at-bol) t) (point))))
            (not (eq my-cursor-point my-overlay-beg))
            (< fci-column my-last-column))
          (overlay-put my-column-overlay 'face
            '(:foreground "Red" :weight bold) ) )
        ;; end of line
        ((= fci-column my-last-column)
          (overlay-put my-column-overlay 'face
            '(:foreground "Red" :weight bold) ) ) 
        ;; cursor
        ((and
            (eq my-cursor-point my-overlay-beg)
            (not (eq (preceding-char) 9))
            (< fci-column my-last-column))
          (overlay-put my-column-overlay 'face
            '(:weight bold) ) )) )))

(defun fci-delete-overlays-region (start end)
  "Delete overlays displaying the fill-column rule between START and END."
  (mapc #'(lambda (o) (if (overlay-get o 'fci) (delete-overlay o)))
        (overlays-in start end))
  (let ((ovs (overlays-in start end)))
    (dolist (ov ovs)
      (unless (member ov (list hl-line-overlay))
        (delete-overlay ov)))) )

(defun fci-redraw-region (start end _ignored)
  "Erase and redraw the fill-column rule between START and END."
  ;; Needed to prevent and then ultimately create a cursor overlay.
  (setq my-cursor-point (point))
  (save-match-data
    (save-excursion
      (let ((inhibit-point-motion-hooks t))
        (goto-char end)
        (setq end (line-beginning-position 2))
        (fci-delete-overlays-region start end)
        (fci-put-overlays-region start end)))))

(defvar quasi-this-command-functions '(next-line previous-line left-char right-char
  self-insert-command newline delete-backward-char delete-forward-char
  indent-for-tab-command mwheel-scroll lawlist-mwheel-scroll end-of-visual-line
  beginning-of-visual-line end-of-buffer beginning-of-buffer lawlist-forward-entity
  lawlist-backward-entity left-word right-word forward-word backward-word
  lawlist-forward-element lawlist-backward-element)
"Variable list of functions that trigger the `fci-quasi-post-command-hook`.")

(defvar fci-quasi-major-mode-inclusions '(text-mode emacs-lisp-mode perl-mode
  js-mode css-mode dired-mode lawlist-tex-mode c-mode html-mode snippet-mode)
"Variable list of major modes where the `fci-quasi-post-command-hook` operates.")

(defun fci-quasi-post-command-hook ()
  (unless (minibufferp)
    (when
      (and
        (memq major-mode fci-quasi-major-mode-inclusions)
        (memq this-command quasi-this-command-functions))
      (fci-mode 1))))

(add-hook 'post-command-hook 'fci-quasi-post-command-hook)

(add-hook 'change-major-mode-hook 'fci-quasi-post-command-hook)

(add-hook 'window-configuration-change-hook 'fci-quasi-post-command-hook)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Example
(source: lawlist.com http://www.lawlist.com/images/fill_column_indicator_b.png)

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

Emacs -- 修改 `fill-column-indicator.el` 以在空白处显示 的相关文章

  • 如何在 Emacs Lisp 中“URL 解码”字符串?

    我有一个像 foo 20bar 这样的字符串 我想要其中的 foo bar 我知道 Emacs Lisp 中必须有一个内置函数来解码 URL 编码的字符串 查询字符串 但我今天找不到它 无论是在我的文档中还是在我的文档中都找不到它 lisp
  • 通过 Emacs 评估 ghci 或 Hugs 中的缓冲区

    在 Emacs 中使用 sml mode 我已经能够使用以下命令将缓冲区内容直接发送到较差的 SML 进程C c C b 现在我只想用 Haskell 做同样的事情 Haskell 模式似乎不支持这一点 所以我想知道 使用 Emacs 和
  • Emacs/Swank/Paredit for Clojure 的温和教程

    我要转向 Emacs 来工作Clojure http en wikipedia org wiki Clojure Lisp 为了能够执行以下操作 我需要在 Emacs 上设置哪些信息 自动匹配 生成相应的右括号 自动缩进 Lisp Cloj
  • 配置jedi不自动完成?

    我在 emacs 中安装了 jedi mode 来进行 python 编辑 因为我发现C and C 对于跳转到定义并返回非常有用 然而 自动完成并不是我想要的 当我尝试在安装了 jedi 的情况下使用 emacs 时 它会不断尝试提供建议
  • 将字符定义为单词边界

    我已经定义了 字符在乳胶模式下充当单词组成部分 我对结果非常满意 唯一困扰我的是像这样的序列 alpha beta被视为单个单词 当然 这是预期的行为 有没有办法让 emacs 将特定字符解释为单词 starter 这样 它将始终被视为其后
  • 为什么在 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
  • 如何让 clangd 转向 c++20

    当没有其他信息时 如何让 clangd 回退到 c 20 例如 在第一次构建之前 cmake 可以生成一个 这是在带有最新 LLVM 的 Arch Linux 上 这是通过 Emacs LSP 运行的 但这应该没有什么区别 你可以加 Com
  • 在 Emacs 中,如何确定哪个包正在加载 Tramp?

    我与 ranp 和 cygwin mount 有一个奇怪的交互 我认为 Emacs 文件名的制表符补全会附加一个额外的 i cygwin https stackoverflow com questions 1705802 emacs tab
  • elisp:从内部函数捕获变量

    我可爱的功能 defun f x lambda y x y 然后 我期望这样 funcall f 2 2 返回 4 但是可惜 我得到了这个 Debugger entered Lisp error void variable x 那么如何从内
  • C# 开发人员有什么理由应该学习 Emacs/Vim 吗?

    我在一家纯粹的 Microsoft 商店担任 C 开发人员 最近 我开始在工作之余的空闲时间使用 Gas 和 Linux 自学汇编 我喜欢摆弄 Linux 尽管我对它还很陌生 我一直听说我应该学习 VIM 或 Emacs 但事实是 我绝对不
  • 将 python2.7 与 Emacs 24.3 和 python-mode.el 一起使用

    我是 Emacs 新手 我正在尝试设置我的 python 环境 到目前为止 我已经了解到在 python 缓冲区中使用 python mode el C c C c将当前缓冲区的内容加载到交互式 python shell 中 显然使用了什么
  • 在 Emacs 中,如何在迷你缓冲区中显示带有字体属性的消息?

    我想在迷你缓冲区中显示彩色文本字符串 但是当我使用 消息 函数时 文本属性被删除 对我有用 message s propertize foo face foreground red 你可能有 message propertize 它将属性化
  • Mac OS High Sierra 下无法打开 pty

    我的问题的本质是 用户程序如何在 Mac OS High Sierra 上打开 pty 例如 dev ptyp0 设备名称的标准 open 似乎不起作用 尽管它的保护是 crw rw rw 上下文是在 Mac OS 下运行 Emacs 在
  • Emacs 打字骨架对插入也许

    在 Eclipse 中 编辑 Java 代码时 如果我输入一个左括号 我会得到一对括号 如果我然后 输入 第二个括号 它不会插入额外的括号 我如何在 emacs 中得到它 Eclipse 编辑器足够聪明 当我输入闭括号时 它知道我刚刚完成了
  • Emacs:导航目录和打开文件的好策略是什么?

    上周 由于必须应对 R 和 Perl 的不同 IDE 我再次感到愤怒 我不喜欢这两种 IDE 也没有使用它们来真正适应 所以我决定尝试 Emacs 我做出这个决定并非没有一定的恐惧 我的主要用途是使用 cperl 来使用 Perl 以及使用
  • 如何让Emacs显示与实际存储的不同的字符?

    我想使用Elisp为Emacs实现动态文本替换 仅替换显示 不替换实际存储的文件 例如 在 LaTeX 文档中 我想输入 alpha 然后让 Emacs 将其显示为 因此更容易阅读 但在结果中 tex文件 我还想要 alpha 代替 被拯救
  • 我可以在 Emacs 的 shell 模式下使用 PowerShell 吗?

    我可以在 emacs 的 shell 模式下使用 powershell 作为 shell 吗 How 请参阅 Jeffrey Snover 的博客文章在 Emacs 内运行的 PowerShell http blogs msdn com p
  • Elisp 获取函数数量?

    我希望能够做到 function arity intern expt 我用谷歌搜索了这个解决方案https github com emacsmirror parser blob master parser fn el https githu
  • Emacs Lisp 中函数名称中的“internal”是什么意思?

    有些人使用双破折号来表示该功能可能会发生变化 函数名称中的双减号 约定在 Emacs Lisp 中意味着什么 https stackoverflow com questions 3180390 what does the double mi

随机推荐