我正在寻求帮助,请调试我的test
功能,以便黄色垂直线看起来与红色线完全相同。我决定排除突出显示标签,因为它们是两(2)个字符宽,它会使垂直线变形。但是,在我尝试排除 tabs
时,我立即失去了对任何文本的突出显示。我尝试修复此问题会破坏蓝色和/或红色行的功能。
简而言之,蓝色和红色行正常工作,但黄色行已被破坏(紧邻右侧)选项卡) - 黄色行应该与红色一行相似。
我的test
功能存在的问题在于以下代码段:
(not (save-excursion (move-to-column my-col-b)
(< 0 (skip-chars-forward "\t"))))
(not (save-excursion (move-to-column my-col-b)
(> 0 (skip-chars-backward "\t")))))
以下函数用于创建下面屏幕截图中描述的缓冲区图像:
(defun test ()
(interactive)
(let* (my-last-column
my-o-beg-a my-o-end-a (my-col-a 3)
my-o-beg-b my-o-end-b (my-col-b 28)
my-o-beg-c my-o-end-c (my-col-c 29) )
(generate-test-buffer)
(goto-char (point-max))
(while (re-search-backward "\n" (point-min) t)
(setq my-last-column (current-column))
(setq my-o-beg-a (progn (move-to-column my-col-a) (point)))
(setq my-o-end-a (+ 1 my-o-beg-a))
(setq my-o-beg-b (progn (move-to-column my-col-b) (point)))
(setq my-o-end-b (+ 1 my-o-beg-b))
(setq my-o-beg-c (progn (move-to-column my-col-c) (point)))
(setq my-o-end-c (+ 1 my-o-beg-c))
(when (and
(< my-col-a my-last-column)
(not (save-excursion (move-to-column my-col-a)
(< 0 (skip-chars-forward "\t"))))
(not (save-excursion (move-to-column my-col-a)
(> 0 (skip-chars-backward "\t")))))
(overlay-put (make-overlay my-o-beg-a my-o-end-a) 'face '(
(background-color . "cyan")
(foreground-color . "black") )))
(when (and
(< my-col-b my-last-column)
(not (save-excursion (move-to-column my-col-b)
(< 0 (skip-chars-forward "\t"))))
(not (save-excursion (move-to-column my-col-b)
(> 0 (skip-chars-backward "\t")))))
(overlay-put (make-overlay my-o-beg-b my-o-end-b) 'face '(
(background-color . "yellow")
(foreground-color . "black") )))
(when (and
(< my-col-b my-last-column)
(not (save-excursion (move-to-column my-col-c)
(< 0 (skip-chars-forward "\t"))))
(not (save-excursion (move-to-column my-col-c)
(> 0 (skip-chars-backward "\t")))))
(overlay-put (make-overlay my-o-beg-c my-o-end-c) 'face '(
(background-color . "red")
(foreground-color . "black") ))) )))
(defun generate-test-buffer ()
(if (get-buffer "foo.el")
(with-current-buffer "foo.el"
(erase-buffer))
(get-buffer-create "foo.el"))
(switch-to-buffer (get-buffer "foo.el"))
(setq whitespace-style '(face space-mark tab-mark newline-mark) )
(setq indent-tabs-mode t)
(setq tab-stop-list (number-sequence 4 200 4))
(setq tab-width 4)
(setq indent-line-function 'insert-tab)
(whitespace-mode t)
(insert ";;;;")
(insert-tabs 1)
(insert "(defun test ()\n;;;;")
(insert-tabs 1)
(insert "(interactive)\n;;;;")
(insert-tabs 2)
(insert "(let* (my-last-column\n;;;;")
(insert-tabs 4)
(insert "my-o-beg-a my-o-end-a (my-col-a 1)\n;;;;")
(insert-tabs 4)
(insert "my-o-beg-b my-o-end-b (my-col-b 11)\n;;;;")
(insert-tabs 4)
(insert "my-o-beg-c my-o-end-c (my-col-c 16) )\n;;;;")
(insert-tabs 3)
(insert "(generate-test-buffer)\n;;;;")
(insert-tabs 3)
(insert "(goto-char (point-max))\n;;;;")
(insert-tabs 3)
(insert "(while (re-search-backward \"\\n\" (point-min) t)\n;;;;")
(insert-tabs 4)
(insert "(setq my-last-column (current-column))\n;;;;")
(insert-tabs 4)
(insert "(setq my-o-beg-a (progn (move-to-column my-col-a) (point)))\n;;;;")
(insert-tabs 4)
(insert "(setq my-o-end-a (+ 1 my-o-beg-a))\n;;;;")
(insert-tabs 4)
(insert "(setq my-o-beg-b (progn (move-to-column my-col-b) (point)))\n;;;;")
(insert-tabs 4)
(insert "(setq my-o-end-b (+ 1 my-o-beg-b))\n;;;;")
(insert-tabs 4)
(insert "(setq my-o-beg-c (progn (move-to-column my-col-c) (point)))\n;;;;")
(insert-tabs 4)
(insert "(setq my-o-end-c (+ 1 my-o-beg-c))\n;;;;")
(insert-tabs 4)
(insert "(when (and\n;;;;")
(insert-tabs 6)
(insert "(< my-col-a my-last-column)\n;;;;")
(insert-tabs 6)
(insert "(not (save-excursion (move-to-column my-col-a)\n;;;;")
(insert-tabs 7)
(insert "(< 0 (skip-chars-forward \"\t\"))))\n;;;;")
(insert-tabs 6)
(insert "(not (save-excursion (move-to-column my-col-a)\n;;;;")
(insert-tabs 7)
(insert "(> 0 (skip-chars-backward \"\t\")))))\n;;;;")
(insert-tabs 5)
(insert "(overlay-put (make-overlay my-o-beg-a my-o-end-a) 'face '(\n;;;;")
(insert-tabs 6)
(insert "(background-color . \"cyan\")\n;;;;")
(insert-tabs 6)
(insert "(foreground-color . \"black\") )))\n;;;;")
(insert-tabs 4)
(insert "(when (and\n;;;;")
(insert-tabs 6)
(insert "(< my-col-b my-last-column)\n;;;;")
(insert-tabs 7)
(insert "(not (save-excursion (move-to-column my-col-b)\n;;;;")
(insert-tabs 7)
(insert "(< 0 (skip-chars-forward \"\t\"))))\n;;;;")
(insert-tabs 6)
(insert "(not (save-excursion (move-to-column my-col-b)\n;;;;")
(insert-tabs 7)
(insert "(> 0 (skip-chars-backward \"\t\")))))\n;;;;")
(insert-tabs 5)
(insert "(overlay-put (make-overlay my-o-beg-b my-o-end-b) 'face '(\n;;;;")
(insert-tabs 6)
(insert "(background-color . \"yellow\")\n;;;;")
(insert-tabs 6)
(insert "(foreground-color . \"black\") )))\n;;;;")
(insert-tabs 4)
(insert "(when (and\n;;;;")
(insert-tabs 6)
(insert "(< my-col-b my-last-column)\n;;;;")
(insert-tabs 6)
(insert "(not (save-excursion (move-to-column my-col-c)\n;;;;")
(insert-tabs 7)
(insert "(< 0 (skip-chars-forward \"\t\"))))\n;;;;")
(insert-tabs 6)
(insert "(not (save-excursion (move-to-column my-col-c)\n;;;;")
(insert-tabs 7)
(insert "(> 0 (skip-chars-backward \"\t\")))))\n;;;;")
(insert-tabs 5)
(insert "(overlay-put (make-overlay my-o-beg-c my-o-end-c) 'face '(\n;;;;")
(insert-tabs 6)
(insert "(background-color . \"red\")\n;;;;")
(insert-tabs 6)
(insert "(foreground-color . \"black\") ))) )))\n" ))
(defun insert-tabs (n)
;; http://stackoverflow.com/a/11830118/2112489
"Inserts N number of tabs"
(interactive "nNumber of tabs: ")
(dotimes (i n)
(indent-for-tab-command)))
答案 0 :(得分:0)
2014年5月3日:初步答案 - 明显的工作解决方案。
标签的字符代码为9
。
标签的宽度等于仅一(1)point
。
标签可以等于一个或更多列,具体取决于tab-width
。
在处理标签时,确定特定column
后面的字符类型是有问题的,因为。 。 。 [当我了解更多时填写]。
在处理标签时,向前移动一(1)point
并回顾也是有问题的,因为。 。 。 [当我了解更多时填写]。
工作解决方案是向前移动一(1)column
并检查前面的字符代码 - 如果它仍然是9
的字符代码,那么不放置一个叠加层(在前一列)。如果目标列已经在非制表符上,那么向前移动一(1)column
并向后看应该在逻辑上产生正确的结果。
(defun test ()
(interactive)
(let* (my-last-column
my-o-beg-a my-o-end-a (my-col-a 3)
my-o-beg-b my-o-end-b (my-col-b 28)
my-o-beg-c my-o-end-c (my-col-c 29) )
(generate-test-buffer)
(goto-char (point-max))
(while (re-search-backward "\n" (point-min) t)
(setq my-last-column (current-column))
(setq my-o-beg-a (progn (move-to-column my-col-a) (point)))
(setq my-o-end-a (+ 1 my-o-beg-a))
(setq my-o-beg-b (progn (move-to-column my-col-b) (point)))
(setq my-o-end-b (+ 1 my-o-beg-b))
(setq my-o-beg-c (progn (move-to-column my-col-c) (point)))
(setq my-o-end-c (+ 1 my-o-beg-c))
(when (and
(< my-col-a my-last-column)
(not (progn (move-to-column (+ 1 my-col-a)) (eq (preceding-char) 9))))
(overlay-put (make-overlay my-o-beg-a my-o-end-a) 'face '(
(background-color . "cyan")
(foreground-color . "black") )))
(when (and
(< my-col-b my-last-column)
(not (progn (move-to-column (+ 1 my-col-b)) (eq (preceding-char) 9))))
(overlay-put (make-overlay my-o-beg-b my-o-end-b) 'face '(
(background-color . "yellow")
(foreground-color . "black") )))
(when (and
(< my-col-b my-last-column)
(not (progn (move-to-column (+ 1 my-col-c)) (eq (preceding-char) 9))))
(overlay-put (make-overlay my-o-beg-c my-o-end-c) 'face '(
(background-color . "red")
(foreground-color . "black") ))) )))