我想尝试自定义编辑模式,但是找不到资料

我想自己做一个编辑模式,但是百度不到多少资料
于是我去翻了一下js-mode的源码,有点力不从心

;;;###autoload
(define-derived-mode js-mode prog-mode "JavaScript"
  "Major mode for editing JavaScript."
  :group 'js
  (setq-local indent-line-function #'js-indent-line)
  (setq-local beginning-of-defun-function #'js-beginning-of-defun)
  (setq-local end-of-defun-function #'js-end-of-defun)
  (setq-local open-paren-in-column-0-is-defun-start nil)
  (setq-local font-lock-defaults
              (list js--font-lock-keywords nil nil nil nil
                    '(font-lock-syntactic-face-function
                      . js-font-lock-syntactic-face-function)))
  (setq-local syntax-propertize-function #'js-syntax-propertize)
  (setq-local prettify-symbols-alist js--prettify-symbols-alist)

  (setq-local parse-sexp-ignore-comments t)
  (setq-local parse-sexp-lookup-properties t)
  (setq-local which-func-imenu-joiner-function #'js--which-func-joiner)

  ;; Comments
  (setq-local comment-start "// ")
  (setq-local comment-end "")
  (setq-local fill-paragraph-function #'js-c-fill-paragraph)
  (setq-local normal-auto-fill-function #'js-do-auto-fill)

  ;; Parse cache
  (add-hook 'before-change-functions #'js--flush-caches t t)

这里我想问点相关链接或教程,主要是对自定义编辑模式的

  • 导入
    1. 怎么设置auto-load,导入这个模式
    2. 怎么根据文件名后缀,导入这个模式
    3. 怎么手动导入
  • 关键字
    1. 怎么设置关键字
    2. 怎么标记关键字
  • 其他
    定义模式只有define-derived-mode这个东西可以用吗,新建一个文件来配置,然后导入可以吗

新增

  • define-derived-mode
    1. 需要的关键字有哪些
    2. 这些关键字功能是什么
1 个赞

你的问题太高深 应该没人懂

怎么设置auto-load

auto-load 的意思是提前载入符号,第一次调用函数的时候才读取文件加载,只需在函数前面加上魔法字符串 ;;;###autoloda 就可以了。

怎么根据文件名后缀,导入这个模式

认真阅读我的这个文件 https://github.com/manateelazycat/lazycat-emacs/blob/master/site-lisp/config/init-mode.el

怎么设置关键字 怎么标记关键字

对着我这个插件依葫芦画瓢:bison/bison.el at master · manateelazycat/bison · GitHub

我是想从c-mode,c++mode,html-mode这些mode里学怎么写mode,以便以后编辑方便点,但是源码里看不懂啊,所以我想看看能不能做个简单的mode练手

http://ergoemacs.org/emacs/elisp_syntax_coloring.html

这个网站的教程都很棒。

2 个赞

这个应该比较容易follow,概括了写一个major mode(可能)需要的各个方面。

1 个赞