[英]emacs major-mode font-lock between characters (parenthesis, quotes, etc)
[英]How to get the character corresponding to syntax in a major-mode
如何在major-mode
獲取與給定語法字符相對應的字符(或字符集)?
例如,我希望能夠獲得轉義字符,例如在大多數模式(如 elisp 或 C)中的 '\\'。我找不到可以返回對應於語法類的字符的函數——在此案例轉義語法類,即。 (string-to-syntax "\\\\") ;; => (9)
(string-to-syntax "\\\\") ;; => (9)
在 Lisp/C 模式下。
那么,我怎么能走另一條路,例如。 (some-function '(9) major-mode) ;; => "\\\\"
語法表是char-tables,你可以使用map-char-table
來檢查語法map-char-table
中的每一條規則,例如,
(defun foo (syntax-code syntax-table)
"Return chars (or char range) with SYNTAX-CODE in SYNTAX-TABLE."
(let (result)
(map-char-table
(lambda (k v)
;; k is either a char or (FROM . TO)
;; v is (SYNTAX-CODE . MATCHING-CHAR)
(when (= (car v) syntax-code)
(push (pcase k
(`(,from . ,to) (list (string from) (string to)))
(_ (string k)))
result)))
syntax-table)
(nreverse result)))
(foo 9 emacs-lisp-mode-syntax-table)
;; => ("\\")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.