help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: automatically change input method based on context


From: Stefan Monnier
Subject: Re: automatically change input method based on context
Date: Fri, 20 Jan 2017 11:42:44 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> 1. Add a `cursor-sensor-functions' property to all the text that is
>    fontified as a comment (and somehow keep this dynamically updated).
[...]
> But I don't know how to go about (1).  Any advice?

Yes: an after-advice.  On `font-lock-fontify-syntactically-region`.

Something along the lines of

    (add-advice 'font-lock-fontify-syntactically-region :after
                #'my-font-lock-comment-to-cursor-sensor)
    (defun my-font-lock-comment-to-cursor-sensor (start end &rest _)
      (save-excursion
        (goto-char start)
        (while (< (point) end)
          (if (not (eq (get-text-property (point) 'face)
                       'font-lock-comment-face))
              (goto-char (or (text-property-any (point) end 'face
                                                'font-lock-comment-face)
                             end))
            (let ((s (point)))
              (goto-char (or (text-property-not-all (point) end 'face
                                                    'font-lock-comment-face)
                             end))
              (put-text-property s (point) 'cursor-sensor-functions
                                 #'my-cursor-sensor-fun))))))
                  

-- Stefan




reply via email to

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