Emacs - 修改'fill-column-indicator.el'以显示空格 [英] Emacs -- modifying `fill-column-indicator.el` to display over whitespace

查看:200
本文介绍了Emacs - 修改'fill-column-indicator.el'以显示空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些帮助,以修改Alp Aker的 fill-column-indicator.el ,以便垂直线在空白处可见(无论是否空格模式是活动的)



以下是图书馆Github资源库的链接:



< a href =https://github.com/alpaker/Fill-Column-Indicator/blob/master/fill-column-indicator.el =nofollow noreferrer> https://github.com/alpaker/Fill -Column-indicator / blob / master / fill-column-indicator.el



目前,空白线不可见垂直线。 / p>

以下代码与 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))

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

示例http://www.lawlist.com/images/fill_column_indicator.png

解决方案

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



2014年5月2日:修改了几个fci模式函数,并包含了前一个草案的部分。



2014 :固定突出显示在选项卡的右侧。加入一个准后命令挂钩来精确控制缓冲区用垂直标尺重新绘制,并删除先前由fci模式使用的钩子。



2014年5月4日:添加与空格模式的部分兼容性,使用(setq whitespace-style')设置(face space-mark tab-mark newline-mark)) tab-mark newline-mark 前台突出显示。但是,由于每个标记跨越多列(但$ 的宽度仅等于1),因此背景未突出显示。






  ;;;;;;; ;;;;;;;;;;;;;;;;;;法律修改;; 
;; http://stackoverflow.com/a/23418459/2112489
;;
;;为了使用这些修改来启用
;;的垂直高亮显示。当前列,需要Alp Aker的库`fill-column-indicator.el`。
;; https://github.com/alpaker/Fill-Column-Indicator
;;以下规定的代码旨在替代函数或变量
;;在上述库中包含相同的名称。有
;;还有以下几个新功能和变量。

(define-minor-mode fci-mode
:group'fci-mode
:lightfci
:global nil
:init-值nil
(如果fci-mode
;;启用
(条件案例错误
(progn
(fci-check-user-options)
(fci-process-display-table)
(fci-set-local-vars)
(fci-get-frame-dimensional)
;;(dolist(hook fci-hook-作业)
;;(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
(如果fci-newline
(1+( - fci-column(length fci-saved-eol)))
fci-column))
(fci-make-overlay-strings)
(fci-update-all-windows t)
(如果linum-mode
-update-current)))
(错误
(fci-mode 0)
(signal(car error)(cdr error))))
;;禁用。
(fci-restore-display-table)
(fci-restore-local-vars)
(dolist(hook fci-hook-assignment)
(remove-hook钩子)(第n个1钩子)(第n个2钩子))
(fci-delete-overlays-buffer)
(dolist(var fci-internal-vars)
(set var nil) ))

(defvar my-column-overlay nil
此缓冲区中使用的覆盖。)
(make-variable-buffer-local'my-column-覆盖)

(defvar my-cursor-point nil
用于防止形成光标覆盖的点
必须在函数`fci-redraw-区域')
(make-variable-buffer-local'my-cursor-point)

(defun fci-put-overlays-region(start end)
放置叠加层,在START和END之间显示填充列规则。
(let *(my-last-column fci-overlay my-overlay-beg my-overlay-end)
(setq cursor-type 空)
(goto-char end)
(while(re-search-backward\\\
start t)
(setq my-last-column rrent-column))
(setq fci-overlay(make-overlay(match-beginning 0)(match-beginning 0)))
(overlay-put fci-overlay'fci t)
(cond
((<我的最后一列fci-limit)
(覆盖放置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
;;文本,不包括标签
((和
(not(save-excursion(move-to-column(+ 1 fci-column))
(eq(previous-char)9)))
(not (我的最后一列))
(< fci-column my-last-column))
(叠加放置my-column-overlay'face
' (:backgroundDarkRed)))
;;选项卡,右侧文本
((和
(不(bobp));;不要尝试超出缓冲区的开始
(not(not(save-excursion(move-to-column fci-column))
(backward-char 1)(eq(char-after点())))
(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
'(:foregroundRed大胆)))
;;标签左边的文本
((和
(不(bobp));;不要试图超出缓冲区的开始
(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
'(:foregroundRed:weight bold)))
;;标签夹在每一边的标签之间
((和
(not(bobp));;不要试图超出缓冲区的开始
(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
'(:foregroundRed:weight bold)))
;;
((= fci-column my-last-column)
(覆盖我的列重叠'面
'(:前景红:体重加粗)) )
;;游标
((和
(eq my-cursor-point my-overlay-beg)
(not(eq(previous-char)9))
(< fci-列我的最后一列))
(叠加我的列重叠'面
'(:重量加粗))))))))

(defun fci -delete-overlays-region(start end)
删除在START和END之间显示填充列规则的覆盖。
(mapc#'(lambda(o)(if(overlay-get o' fc)($)
(开始的覆盖))
(let((ovs(覆盖在起始端)))
(dolist(ov ovs)
(except(member ov(list hl-line-overlay))
(delete-overlay ov)))))

(defun fci-redraw-region(start end
删除并重绘START和END之间的填充列规则
;;需要防止然后最终创建一个光标覆盖
(setq my-cursor-point(点))
(save-match-data
(save-excursion
(let((inhibiti t-point-motion-hooks t))
(goto-char end)
(setq end(line-begin-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
开始视觉缓冲区起始缓冲区起始缓冲区法律清单 - 前向实体
法律列表 - 后向实体左字右侧词前向词向后词
lawlist- forward-element lawlist-backward-element)
触发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)
`fci。'的主要模式的可变列表-quasi-post-command-hook`操作。)

(defun fci-quasi-post-command-hook()
(unless(minibufferp)
b $ b(和
(memq major-mode fci-quasi-major-mode-inclusions)
(memq this-command quasi-this-command-functions))
(fci模式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)

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






示例http://www.lawlist.com/images/fill_column_indicator_b.png


I am looking for some assistance, please, to modify fill-column-indicator.el by Alp Aker so that the vertical line is visible over whitespace (regardless of whether whitespace-mode is active).

Here is the link to the Github repository for the library:

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

At the present time, the vertical line is not visible over whitespace.

The following code, when combined with fill-column-indicator.el, creates a vertical line that tracks the current cursor column position. I've examined the code of fill-column-indicator.el, however, I haven't been able to locate the portion of code that prevents the vertical line from appearing when whitespace is present.

(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 http://www.lawlist.com/images/fill_column_indicator.png

解决方案

May 1, 2014:  Created a first working draft.

May 2, 2014:  Modified several fci-mode functions, and portions of the prior draft have been included.

May 3, 2014:  Fixed highlighting of column to the right of a tab. Incorporated a quasi-post-command-hook to control precisely when the buffer is redrawn with the vertical ruler, and removed the hooks previously used by fci-mode.

May 4, 2014:  Added partial compatibility with whitespace-mode using settings of (setq whitespace-style '(face space-mark tab-mark newline-mark) ). The foreground for tab-mark and newline-mark are highlighted. However, the background is not highlighted due to the fact each mark spans more than one column (yet the width of point is only equal to one).


;;;;;;;;;;;;;;;;;;;;;;;;; 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 http://www.lawlist.com/images/fill_column_indicator_b.png

这篇关于Emacs - 修改'fill-column-indicator.el'以显示空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆