我需要突出显示emacs的工具,以便在使用它时标记文件中的某些行.它应该是smth,M-s h l但应该基于行号而不是正则表达式.我想要突出显示当前行,但是hl-line-mode不适合,因为我需要突出显示许多行,每次按下每个行上的特定键.
Pas*_*ten 13
我刚刚写了以下内容:
(defun find-overlays-specifying (prop pos)
(let ((overlays (overlays-at pos))
found)
(while overlays
(let ((overlay (car overlays)))
(if (overlay-get overlay prop)
(setq found (cons overlay found))))
(setq overlays (cdr overlays)))
found))
(defun highlight-or-dehighlight-line ()
(interactive)
(if (find-overlays-specifying
'line-highlight-overlay-marker
(line-beginning-position))
(remove-overlays (line-beginning-position) (+ 1 (line-end-position)))
(let ((overlay-highlight (make-overlay
(line-beginning-position)
(+ 1 (line-end-position)))))
(overlay-put overlay-highlight 'face '(:background "lightgreen"))
(overlay-put overlay-highlight 'line-highlight-overlay-marker t))))
(global-set-key [f8] 'highlight-or-dehighlight-line)
Run Code Online (Sandbox Code Playgroud)
(此处查找 - 覆盖 - 指定来自手册页)
它将突出显示当前行,当再次使用时,它将删除它.
也许以下内容也很有用:从缓冲区中删除所有高亮显示(可能很危险,如果突出显示重要内容,您可能不需要它)
(defun remove-all-highlight ()
(interactive)
(remove-overlays (point-min) (point-max))
)
(global-set-key [f9] 'remove-all-highlight)
Run Code Online (Sandbox Code Playgroud)
syo*_*hex 13
您可以使用bm.el.您可以从MELPA安装bm.el.
bm.el bm-toggle用于突出显示和取消当前行的高亮显示.bm.el还提供bm-bookmark-regexp仅突出显示匹配线的突出显示.你可以用bm-previous和跳过突出显示的行bm-next
以下是bm.el的示例配置
(require 'bm)
(global-set-key (kbd "<f5>") 'bm-toggle)
(global-set-key (kbd "<f6>") 'bm-previous)
(global-set-key (kbd "<f7>") 'bm-next)
(global-set-key (kbd "<f8>") 'bm-bookmark-regexp)
Run Code Online (Sandbox Code Playgroud)