【发布时间】:2011-02-27 13:47:33
【问题描述】:
我正在为一种语言(又名 mydsl)开发一个 emacs 主模式。但是,由于某种原因,使用 xahlee 网站上的技术似乎不起作用(可能是较旧的 emacs 方言..)
我要解决的关键问题是 (1) 突出显示 cmets 不起作用,(2) 使用 regexp-opt 行不起作用。
我查看了 GNU 手册并查看了 cc-mode 和 elisp mode...这些比我需要的要复杂得多。
;;;Standard # to newline comment
;;;Eventually should also have %% to %% multiline block comments
(defun mydsl-comment-dwim (arg)
"comment or uncomment"
(interactive "*P")
(require 'newcomment)
(let
((deactivate-mark nil)
(comment-start "#")
(comment-end "")
comment-dwim arg)))
(defvar mydsl-events
'("reservedword1"
"reservedword2"))
(defvar mydsl-keywords
'("other-keyword" "another-keyword"))
;;Highlight various elements
(setq mydsl-hilite
'(
; stuff between "
("\"\\.\\*\\?" . font-lock-string-face)
; : , ; { } => @ $ = are all special elements
(":\\|,\\|;\\|{\\|}\\|=>\\|@\\|$\\|=" . font-lock-keyword-face)
( ,(regexp-opt mydsl-keywords 'words) . font-lock-builtin-face)
( ,(regexp-opt mydsl-events 'words) . font-lock-constant-face)
))
(defvar mydsl-tab-width nil "Width of a tab for MYDSL mode")
(define-derived-mode mydsl-mode fundamental-mode
"MYDSL mode is a major mode for editing MYDSL files"
;Recommended by manual
(kill-all-local-variables)
(setq mode-name "MYDSL script")
(setq font-lock-defaults '((mydsl-hilite)))
(if (null mydsl-tab-width)
(setq tab-width mydsl-tab-width)
(setq tab-width default-tab-width)
)
;Comment definitions
(define-key mydsl-mode-map [remap comment-dwim] 'mydsl-comment-dwim)
(modify-syntax-entry ?# "< b" mydsl-mode-syntax-table)
(modify-syntax-entry ?\n "> b" mydsl-mode-syntax-table)
;;A gnu-correct program will have some sort of hook call here.
)
(provide 'mydsl-mode)
【问题讨论】:
-
你知道 Xah 的网站是讽刺的,对吧?
-
@jrockway - 他的 emacs 东西似乎大多是可靠的。我不确定你的意思。
-
我不能代表 jrockway,虽然我发现 Xah 关于 Emacs 的信息多产且用心良苦,但它经常偏离 Emacs lisp 规范和约定,我认为它们教错了东西。例如
mydsl-comment-dwim是自定义comment行为的错误方法。同样,在 Xah 的页面上,我很快找到了一个wrap-markup定义,它(虽然是功能性的)打破了接受参数并使用(interactive "r")传递区域的约定。
标签: emacs major-mode