emacs-devel
[Top][All Lists]
Advanced

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

Re: region-based face-remapping


From: Stefan Monnier
Subject: Re: region-based face-remapping
Date: Mon, 15 Jan 2024 15:17:55 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

>> IIUC you're discussing features where the appearance of parts of the
>> buffer depends on the position of point.  The main design issue with it
>> is what to do when the buffer is displayed in several windows (so there
>> are several points).  Depending on this, the implementation strategy may
>> need to be very different.
>
> That’s a very good point that I had not considered.  In my case, the
> selected widow would take precedence, and other windows just get what
> they get.

While rendering window A, the selected window is always window A.
But yeah, I guess you could use jit-lock as in:

      ... call (jit-lock-register #'my-region-hl-fontify)
      ... and also make sure `my-region-hl` is placed last on
          `jit-lock-functions` (jit-lock currently doesn't offer
          a clean way to do that, sorry).
      ... and use `post-command-hook` or `pre-redisplay-functions`
      ... to call `my-region-hl-update-point`.

    (defvar-local my-region-hl-pos nil)

    (defun my-region-hl-update-point ()
      ;; compute the highlighted region according to point.
      (let ((beg ...)
            (end ...))
        (unless (and my-region-hl-pos
                     (= beg (car my-region-hl-pos))
                     (= end (cdr my-region-hl-pos)))
          (put-text-property (min beg (car my-region-hl-pos))
                             (max beg (car my-region-hl-pos))
                             'fontified nil))
          (put-text-property (min end (cdr my-region-hl-pos))
                             (max end (cdr my-region-hl-pos))
                             'fontified nil)
          (setq my-region-hl-pos
                (cons (copy-marker beg) (copy-marker end)))))

    (defun my-region-hl-fontify (beg end)
      (when my-region-hl-pos
        (setq beg (max beg (car my-region-hl-pos)))
        (setq end (min end (cdr my-region-hl-pos)))
        (when (> end beg)
          ... modify faces between `beg` and `end`.
          )))
          
        
-- Stefan




reply via email to

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