【问题标题】:Highlighting columns in emacs在 emacs 中突出显示列
【发布时间】:2016-04-29 11:23:58
【问题描述】:

这是我的目标示例:

如何自定义 .emacs 以使用一种背景/字体颜色突出显示第 1-10 列,使用不同背景/字体颜色突出显示第 11-20 列等?我不确定什么是好的起点。我看到了这个帖子,但它完全没有需要的东西。 How can I make emacs highlight lines that go over 80 chars?

【问题讨论】:

标签: emacs


【解决方案1】:

我确信有一个更优雅的解决方案,但我使用了来自column-marker library 的部分。以下是相关部分:

(defun column-marker-find (col)
  "Defines a function to locate a character in column COL. Returns the function symbol, named `column-marker-move-to-COL'."
  (let ((fn-symb  (intern (format "column-marker-move-to-%d" col))))
    (fset `,fn-symb
          `(lambda (end)
             (let ((start (point)))
               (when (> end (point-max)) (setq end (point-max)))
           (message "this -> %d" (point-max))

               ;; Try to keep `move-to-column' from going backward, though it still can.
               (unless (< (current-column) ,col) (forward-line 1))

               ;; Again, don't go backward.  Try to move to correct column.
               (when (< (current-column) ,col) (move-to-column ,col))

               ;; If not at target column, try to move to it.
               (while (and (< (current-column) ,col) (< (point) end)
                           (= 0 (+ (forward-line 1) (current-column)))) ; Should be bol.
                 (move-to-column ,col))

               ;; If at target column, not past end, and not prior to start,
               ;; then set match data and return t.  Otherwise go to start
               ;; and return nil.
               (if (and (<= ,col (current-column)) (<= (point) end) (> (point) start) )
                   (progn (set-match-data (list (1- (point)) (point)))
                          t)            ; Return t.
         (message "column %d" (current-column))
                 (goto-char start)
                 nil)))) ; Return nil.
    fn-symb)
  )


(defun column-marker-internal (sym col &optional face)
  "SYM is the symbol for holding the column marker context. COL is the column in which a marker should be set. Supplying nil or 0 for COL turns off the marker. FACE is the face to use.  If nil, then face `column-marker-1' is used."
  (when col                             ; Generate a new column marker
    (set sym `((,(column-marker-find col) (0 ',face prepend t))))
    (font-lock-add-keywords nil (symbol-value sym) t)
    )
  (font-lock-fontify-buffer)
  )

并部署列突出显示:

  (defface column-marker '((t (:background "gray"))) "" :group 'faces)  
  (defvar column-marker-face 'column-marker "" )
  (setq num 0)
  (while (< num 10)
    (column-marker-internal 'column-marker (+ 11 num) column-marker-face)
    (setq num (1+ num)))

【讨论】:

    猜你喜欢
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 2011-02-14
    相关资源
    最近更新 更多