如何检查点之前的字符是否等于“ \
”
(defun comment-latex ()
(interactive)
(if (region-active-p)
(comment-region (region-beginning) (region-end))
(if (= (char-before) ("\\") ;; how to fix this sentence?
(insert "%")
(if (= (point) (line-beginning-position)) ;; this part works
(insert "% ")
(end-of-line)
(insert " % "))))
)
(global-set-key LaTeX-mode-map (kbd "%") 'comment-latex)
作为示例的代码应该执行以下操作:
1)如果选择了区域,则应注释该区域。
2)如果点之前的字符是“ \
”,则应在点处插入正常的%。
3)如果点在行首,插入一个“ %
”
4) 如果点在其他任何地方,则转到句末并插入“ SPC
%
SPC
”