在emacs主模式下正确高亮显示

在emacs主模式下正确高亮显示,emacs,major-mode,Emacs,Major Mode,我正在开发一种语言的emacs主要模式(也称为mydsl)。然而,由于某些原因,在Xahle的站点上使用这些技术似乎不起作用(可能是旧的emacs方言…) 我要解决的关键问题是:(1)突出显示注释不起作用;(2)使用regexp opt行不起作用 我已经阅读了GNU手册并查看了cc模式和elisp模式。。。这些比我需要的要复杂得多 ;;;Standard # to newline comment ;;;Eventually should also have %% to %% multiline

我正在开发一种语言的emacs主要模式(也称为mydsl)。然而,由于某些原因,在Xahle的站点上使用这些技术似乎不起作用(可能是旧的emacs方言…)

我要解决的关键问题是:(1)突出显示注释不起作用;(2)使用
regexp opt
行不起作用

我已经阅读了GNU手册并查看了cc模式和elisp模式。。。这些比我需要的要复杂得多

;;;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)
;;;标准#至新行注释
;;;最终还应该有%%到%%的多行块注释
(定义mydsl注释dwim(arg)
“注释或取消注释”
(互动“*P”)
(需要“新成员”)
(让
((停用标记零)
(注释开始“#”)
(注释结束“”)
注释(dwim arg)))
(defvar mydsl事件)
“(“保留订单1”
“储备订单2”))
(defvar mydsl关键字)
“(“其他关键字”“其他关键字”))
;;突出各种元素
(setq mydsl黑云母
'(
;介于
(“\”\\.\*\?”.font锁定字符串面)
;:,;{}=>@$=都是特殊元素
(“:\ \ \ \ \;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \=”。字体锁定关键字面)
(,(regexp opt mydsl关键字的单词)。字体锁定内置面)
(,(regexp opt mydsl事件的单词)。字体锁定常量面)
))
(defvar mydsl tab width nil“mydsl模式的选项卡宽度”)
(定义派生模式mydsl模式基本模式
“MYDSL模式是编辑MYDSL文件的主要模式”
;由手册推荐
(杀死所有局部变量)
(setq模式名称“MYDSL脚本”)
(setq字体锁定默认值'((mydsl hilite)))
(如果(空mydsl选项卡宽度)
(setq制表符宽度mydsl制表符宽度)
(设置选项卡宽度默认选项卡宽度)
)
;注释定义
(定义键mydsl模式映射[重新映射注释dwim]“mydsl注释dwim”)
(修改语法条目?#“b”mydsl模式语法表)
一个gnu正确的程序在这里会有某种钩子调用。
)
(提供“mydsl模式”)

您的代码中有几个语法问题,但您的代码几乎是正确的。这是我编辑过的版本,对于
mydsl模式下的缓冲区来说似乎是正确的:

; No changes to the simple vars
(defvar mydsl-events
  '("reservedword1"  
    "reservedword2"))

(defvar mydsl-keywords
  '("other-keyword" "another-keyword"))

;; I'd probably put in a default that you want, as opposed to nil
(defvar mydsl-tab-width nil "Width of a tab for MYDSL mode")

;; Two small edits.
;; First is to put an extra set of parens () around the list
;; which is the format that font-lock-defaults wants
;; Second, you used ' (quote) at the outermost level where you wanted ` (backquote)
;; you were very close
(defvar mydsl-font-lock-defaults
  `((
     ;; 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)
     )))

(define-derived-mode mydsl-mode fundamental-mode "MYDSL script"
  "MYDSL mode is a major mode for editing MYDSL  files"

  ;; fundamental-mode kills all local variables, no need to do it again
  (setq mode-name "MYDSL script")

  ;; you again used quote when you had '((mydsl-hilite))
  ;; I just updated the variable to have the proper nesting (as noted above)
  ;; and use the value directly here
  (setq font-lock-defaults mydsl-font-lock-defaults)

  ;; when there's an override, use it
  ;; otherwise it gets the default value
  (when mydsl-tab-width
    (setq tab-width mydsl-tab-width))

  ;; for comments
  ;; overriding these vars gets you what (I think) you want
  ;; they're made buffer local when you set them
  (setq comment-start "#")
  (setq comment-end "")

  (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)
;对简单变量没有任何更改
(defvar mydsl事件)
“(“保留订单1”
“储备订单2”))
(defvar mydsl关键字)
“(“其他关键字”“其他关键字”))
;; 我可能会输入一个你想要的默认值,而不是零
(defvar mydsl tab width nil“mydsl模式的选项卡宽度”)
;; 两个小编辑。
;; 首先是在列表周围放置一组额外的paren()
;; 字体锁定默认需要的格式是什么
;; 第二,您在最外层使用了“(引号),在最外层需要使用“(反引号)
;; 你很接近
(defvar mydsl字体锁定默认值
`((
;介于
(“\”\\.\*\?”.font锁定字符串面)
;;;:,;{}=>@$=都是特殊元素
(“:\ \ \ \ \;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \=”。字体锁定关键字面)
(,(regexp opt mydsl关键字的单词)。字体锁定内置面)
(,(regexp opt mydsl事件的单词)。字体锁定常量面)
)))
(定义派生模式mydsl模式基本模式“mydsl脚本”
“MYDSL模式是编辑MYDSL文件的主要模式”
基本模式杀死所有局部变量,无需再次执行
(setq模式名称“MYDSL脚本”)
;您在使用“((mydsl hilite))时再次使用引号
;我刚刚更新了变量,使其具有正确的嵌套(如上所述)
;并在此处直接使用该值
(setq字体锁定默认值mydsl字体锁定默认值)
当有覆盖时,使用它
;否则将获取默认值
(当mydsl选项卡宽度
(setq制表符宽度mydsl制表符宽度))
征求意见
覆盖这些变量可以得到(我认为)你想要的
当您设置它们时,它们被设置为本地缓冲区
(setq注释开始“#”)
(setq注释结束“”)
(修改语法条目?#“b”mydsl模式语法表)
一个gnu正确的程序在这里会有某种钩子调用。
)
(提供“mydsl模式”)

modify syntax条目内容来自。修改语法条目的东西是-我想是吧?管理注释处理的正确方法是,否则emacs将在注释中突出显示代码。无论如何,注释代码不起作用。注意-注释dwim重新映射允许注释dwim在mydsl模式下正常工作。根据Xahle的说法,modify syntax条目描述符应该创建注释高亮显示。@PaulNathan我看不出我所拥有的(设置注释变量并仅在本地使用
comment dwim
)与Xah所写的有什么区别
comment dwim
可以使用
#
字符和我的代码注释出一个区域。Emacs 23.1。@Trey-Huh。我找到了
注释dwim
,但语法表修改仍然不起作用。我觉得我错过了一些非常明显的东西。我试过不同的颜色主题。我有最新的emacs 23。@Paul语法表修改不起作用是什么意思?需要更多信息。我在一个新的Emacs中注释掉
modify syntax条目
行,并获得适当的注释突出显示。你确实意识到Xah的站点是讽刺的,对吧?@jrockway-他的Emacs内容似乎大部分都是可靠的。我不知道你的意思。我不能代表jrockway说话,虽然我发现Xah关于Emacs的信息丰富且用意良好,但它经常偏离Emacs lisp规范和约定,我认为这是错误的。e、 g.
mydsl注释dwim
是定制
comment
行为的错误方式。类似地,在Xah的页面上,我很快找到了一个
wrap markup
定义,该定义(虽然是功能性的)打破了获取参数和使用
(交互式“r”)
在区域中传递的惯例。