DevelopmentCool2449 / colorful-mode

🎨Preview any color in your buffer
GNU General Public License v3.0
58 stars 5 forks source link

feature request: only take effect in some part of current buffer #6

Closed liuyinz closed 3 months ago

liuyinz commented 3 months ago

Thanks for your great package ! Is there any methods to make font-lock-add-keywords only take effect in part of current buffer ?

e.g. When I select a region to multi-line edit, I hope colorful-mode disabled in the region so that my multi-cursor willl align on same column, otherwise it appears as follow:

截屏2024-06-28 23 34 36
DevelopmentCool2449 commented 3 months ago

Hello @liuyinz ,

Is there any methods to make font-lock-add-keywords only take effect in part of current buffer ? I hope colorful-mode disabled in the region so that my multi-cursor willl align on same column, otherwise it appears as follow:

Sorry, i don't think it would be a good idea implement that feature since i find it problematic. I don't know if the other users that use colorful-mode agree about integrating this.

However i've made a little hook that you can integrate in your config (i'll documenting in the README file after working on the next release):

(add-hook 'post-command-hook
          (defun colorful-delete-color-on-active-mark ()
            (when-let (colorful-mode
                       (beg (region-beginning))
                       (end (region-end)))
              (if mark-active
                  (dolist (ov (overlays-in beg end))
                    (when (overlay-get ov 'colorful--overlay)
                      (colorful--delete-overlay ov)))
                (save-excursion
                  (font-lock-fontify-region beg end)))))
          nil t)
liuyinz commented 3 months ago

Thanks for your advice, my solution for edit-commands meow-grab as follow:

;; HACK disable colorful-mode in meow-grab command
(with-eval-after-load 'colorful-mode
  (defun av/colorful-toggle-on-meow-grab ()
    (when (bound-and-true-p colorful-mode)
      (when (secondary-selection-exist-p)
        (save-excursion
          (font-lock-fontify-region (overlay-start mouse-secondary-overlay)
                                    (overlay-end mouse-secondary-overlay))))
      (when (region-active-p)
        (dolist (ov (overlays-in (region-beginning) (region-end)))
          (when (overlay-get ov 'colorful--overlay)
            (colorful--delete-overlay ov))))))
  (advice-add 'meow-grab :before #'av/colorful-toggle-on-meow-grab))

meow-grab use secondary-selection overlay for editing.

DevelopmentCool2449 commented 3 months ago

Thanks for your advice, my solution for edit-commands meow-grab as follow:

;; HACK disable colorful-mode in meow-grab command
(with-eval-after-load 'colorful-mode
  (defun av/colorful-toggle-on-meow-grab ()
    (when (bound-and-true-p colorful-mode)
      (when (secondary-selection-exist-p)
        (save-excursion
          (font-lock-fontify-region (overlay-start mouse-secondary-overlay)
                                    (overlay-end mouse-secondary-overlay))))
      (when (region-active-p)
        (dolist (ov (overlays-in (region-beginning) (region-end)))
          (when (overlay-get ov 'colorful--overlay)
            (colorful--delete-overlay ov))))))
  (advice-add 'meow-grab :before #'av/colorful-toggle-on-meow-grab))

meow-grab use secondary-selection overlay for editing.

If your hack works well, then i can close this issue, since i don't use meow