meain / dotfiles

If there is a shell, there is a way!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlight yanked region in Emacs - vertical selection highlight is wrong

mat-r opened this issue · comments

commented

Hi, I found your article Highlight yanked region in Emacs when searching a way to highlight the selection when yanking in Emacs. I am also coming from vim/neovim and used the same auto command as you.

First, thank you for the article. However, when I do a vertical selection with C-v, what is highlighted is the first line from the first character, all the intermediate lines and the last lines to the last character.

Screen.Recording.2021-05-08.at.17.06.18.mov

I do not have the knowledge to fix this in Elisp so I just let you know. Even if a fix would be nice I do not expect anything so feel free to close this if needed.

Doing this with pulse.el is a bit tricky. The function that I am using here to highlight just takes a start and end position and does not account for block("rectangular" in Emacs world) selection. One thing we could do is to highlight each of the line, computing the start and end positions. But the issue with this is that pulse.el at any time only supports one single highlight timer. Will probably have to use some other package other than pulse.el to do this. The code like below should ideally work, but since the previous timers for pulsing gets deleted it ends up highlighting just the last line.

  (if (eq evil-visual-selection 'block)
      (let* ((start-line (line-number-at-pos beg))
             (end-line (line-number-at-pos end))
             (start-column (save-excursion
                             (goto-char beg)
                             (current-column)))
             (end-column (save-excursion
                           (goto-char end)
                           (current-column))))
        (save-excursion
          (while (< start-line end-line)
            (setq start-line (+ 1 start-line))
            (goto-line start-line)
            (let ((s (save-excursion
                       (move-to-column start-column)
                       (point)))
                  (e (save-excursion
                       (move-to-column end-column)
                       (point))))
              (pulse-momentary-highlight-region s e 'company-template-field)))))  ; this function should not delete previous highlight
  (pulse-momentary-highlight-region beg end
                                    'company-template-field))

There is another package which does something similar(evil-goggles) and when I went hunting for this there all I saw there was a TODO item 😅.

commented

Interesting. I will check this package. Anyway, for the moment I can live with it!