emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: electric-pair-mode as a minor mode?


From: João Távora
Subject: Re: electric-pair-mode as a minor mode?
Date: Mon, 30 Mar 2015 11:46:24 +0100

Stefan Monnier <address@hidden> writes:

> I guess you'd d have to use syntax-propertize-function to catch&handle the
> "unusual cases". 

Here's my current attempt.

    (add-hook 'message-mode-hook 'joaot/setup-message-mode-syntax)
     
    (defun joaot/setup-message-mode-syntax ()
      (setq-local syntax-propertize-function 'message--syntax-propertize
      (setq-local parse-sexp-lookup-properties t)
      (setq-local parse-sexp-ignore-comments t))
     
    (defun message--syntax-propertize (beg end)
      ;; first, remove all `syntax-table' properties
      ;;
      (remove-text-properties beg end '(syntax-table nil))
      ;; propertize smileys as "generic comments"
      ;;
      (goto-char beg)
      (while (search-forward-regexp ":-?[()]" end 'noerror)
        (add-text-properties (match-beginning 0) (match-end 0)
                             '(syntax-table (14 . nil))))
      ;; idem for citations
      ;;
      (goto-char beg)
      (while (search-forward-regexp
              (concat "^" message-cite-prefix-regexp ".*")
              end 'noerror)
        (add-text-properties (match-beginning 0) (match-end 0)
                             '(syntax-table (14 . nil)))))


It seems works well but:

* I have no idea how "expensive" this naive approach is.

* Although the `syntax-table' property seems to be set correctly, and
  both show-paren mode and electric-pair-mode seem to dtrt, I saw many
  cases where M-: (nth 4 (syntax-ppss)) didn't return non-nil when it
  should have, and vice versa. Is this part of the
  `parse-sexp-lookup-properties' sematics, that `syntax-ppss' becomes
  meaningless?
  
* I'm using `message-cite-prefix-regexp' to detect citations. It's what
  font-lock in lisp/gnus/message.el uses so it seems ideal. But there
  are also a lot of vars like `message-yank-prefix', whose docstring
  contains the following line which baffles me:

>    Fix `message-cite-prefix-regexp' if it is set to an abnormal value.

Can you have a look and give it some testing?

João



reply via email to

[Prev in Thread] Current Thread [Next in Thread]