* Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
@ 2022-08-30 21:11 Jean Louis
2022-08-31 0:39 ` Michael Heerdegen
0 siblings, 1 reply; 7+ messages in thread
From: Jean Louis @ 2022-08-30 21:11 UTC (permalink / raw)
To: Help GNU Emacs
I am trying to understand this. Here is the problem, step by step:
1. {M-x package-list-packages RET}
2. {M-x highlight-regexp RET gnu RET RET} this will highlight word
"gnu" everywhere
3. Click to sort the list by column like "Version"
4. Highlights are lost, and I can understand that.
But {M-x highlight-regexp RET gnu RET RET} does not work any more
at this point.
This was already on the mailing list, but I have forgot what to do to
remedy this.
I do need to make sure that some highlights appear after sorting of
tabulated-list-mode.
Does anybody have clue why is this happening?
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
2022-08-30 21:11 Why M-x highlight-regexp does not work after sort in tabulated-list-mode? Jean Louis
@ 2022-08-31 0:39 ` Michael Heerdegen
2022-08-31 4:03 ` Jean Louis
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Michael Heerdegen @ 2022-08-31 0:39 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> I am trying to understand this. Here is the problem, step by step:
>
> 1. {M-x package-list-packages RET}
>
> 2. {M-x highlight-regexp RET gnu RET RET} this will highlight word
> "gnu" everywhere
>
> 3. Click to sort the list by column like "Version"
>
> 4. Highlights are lost, and I can understand that.
>
> But {M-x highlight-regexp RET gnu RET RET} does not work any more
> at this point.
>
> This was already on the mailing list, but I have forgot what to do to
> remedy this.
It was your Bug#53771. We didn't come to a nice solution in that
report, so your memory is fine in that regard.
The problem was that you are working with a non-font-lock-mode buffer,
so highlighting is not automatically updated. OTOH, repeating
highlight-regexp with the same pattern does nothing. So I think you
must first remove the pattern (unhighlight) and then add it again. You
can try to do this automatically.
Michael.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
2022-08-31 0:39 ` Michael Heerdegen
@ 2022-08-31 4:03 ` Jean Louis
2022-08-31 4:19 ` Jean Louis
2022-08-31 21:09 ` Jean Louis
2 siblings, 0 replies; 7+ messages in thread
From: Jean Louis @ 2022-08-31 4:03 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs, larsi, 53771
* Michael Heerdegen <michael_heerdegen@web.de> [2022-08-31 03:41]:
> It was your Bug#53771. We didn't come to a nice solution in that
> report, so your memory is fine in that regard.
Thank you for reminder. I found it now here:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=53771#27
> The problem was that you are working with a non-font-lock-mode buffer,
> so highlighting is not automatically updated. OTOH, repeating
> highlight-regexp with the same pattern does nothing. So I think you
> must first remove the pattern (unhighlight) and then add it again. You
> can try to do this automatically.
I do think that tabulated list mode should then check for highlighting
patterns and then apply it.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
2022-08-31 0:39 ` Michael Heerdegen
2022-08-31 4:03 ` Jean Louis
@ 2022-08-31 4:19 ` Jean Louis
2022-08-31 4:29 ` Jean Louis
2022-09-02 0:11 ` bug#53771: " Michael Heerdegen
2022-08-31 21:09 ` Jean Louis
2 siblings, 2 replies; 7+ messages in thread
From: Jean Louis @ 2022-08-31 4:19 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs, larsi, 53771
* Michael Heerdegen <michael_heerdegen@web.de> [2022-08-31 03:41]:
> The problem was that you are working with a non-font-lock-mode buffer,
> so highlighting is not automatically updated. OTOH, repeating
> highlight-regexp with the same pattern does nothing. So I think you
> must first remove the pattern (unhighlight) and then add it again. You
> can try to do this automatically.
Problem is that I do not see that `S' for sorting in
`tabulated-list-mode' runs any hook.
Do you think that is error, and that hook shall be run after sorting?
If I place my function to highlight stuff on the end of
`tabulated-list-sort' then it works well.
I think that `tabulated-list-sort' shall run the derived mode's hook.
(defun hyperscope-highlight (&optional highlight-list)
(setq hi-lock-interactive-patterns nil)
(setq hi-lock-interactive-lighters nil)
(let* ((list (hyperscope-action-status-name-list))
(list (append list '("SUCCESS" "DISEASE" "FOLLOW-UP")))
(list (append list highlight-list)))
(rcd-highlight-list list)))
(defun tabulated-list-sort (&optional n)
"Sort Tabulated List entries by the column at point.
With a numeric prefix argument N, sort the Nth column.
If the numeric prefix is -1, restore order the list was
originally displayed in."
(interactive "P")
(when (and n
(or (>= n (length tabulated-list-format))
(< n -1)))
(user-error "Invalid column number"))
(if (equal n -1)
;; Restore original order.
(progn
(unless tabulated-list--original-order
(error "Order is already in original order"))
(setq tabulated-list-entries
(sort tabulated-list-entries
(lambda (e1 e2)
(< (gethash e1 tabulated-list--original-order)
(gethash e2 tabulated-list--original-order)))))
(setq tabulated-list-sort-key nil)
(tabulated-list-init-header)
(tabulated-list-print t))
;; Sort based on a column name.
(let ((name (if n
(car (aref tabulated-list-format n))
(get-text-property (point)
'tabulated-list-column-name))))
(if (nth 2 (assoc name (append tabulated-list-format nil)))
(tabulated-list--sort-by-column-name name)
(user-error "Cannot sort by %s" name)))))
(defun tabulated-list--sort-by-column-name (name)
(when (and name (derived-mode-p 'tabulated-list-mode))
(unless tabulated-list--original-order
;; Store the original order so that we can restore it later.
(setq tabulated-list--original-order (make-hash-table))
(cl-loop for elem in tabulated-list-entries
for i from 0
do (setf (gethash elem tabulated-list--original-order) i)))
;; Flip the sort order on a second click.
(if (equal name (car tabulated-list-sort-key))
(setcdr tabulated-list-sort-key
(not (cdr tabulated-list-sort-key)))
(setq tabulated-list-sort-key (cons name nil)))
(tabulated-list-init-header)
(tabulated-list-print t)
(hyperscope-highlight) ;; My function
))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
2022-08-31 4:19 ` Jean Louis
@ 2022-08-31 4:29 ` Jean Louis
2022-09-02 0:11 ` bug#53771: " Michael Heerdegen
1 sibling, 0 replies; 7+ messages in thread
From: Jean Louis @ 2022-08-31 4:29 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs, larsi, 53771
* Jean Louis <bugs@gnu.support> [2022-08-31 07:21]:
> I think that `tabulated-list-sort' shall run the derived mode's hook.
And function `tabulated-list-col-sort' shall run the derived mode's
hook as that one is invoked by mouse.
The manual said that hooks shall be favored before `advice-add'. As
that seem to be one way to solve my problem if highlighting after
sorting of tabulated list mode.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#53771: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
2022-08-31 4:19 ` Jean Louis
2022-08-31 4:29 ` Jean Louis
@ 2022-09-02 0:11 ` Michael Heerdegen
1 sibling, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2022-09-02 0:11 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: larsi, 53771
Jean Louis <bugs@gnu.support> writes:
> Do you think that is error, and that hook shall be run after sorting?
I don't know what exactly you are doing, so it's hard to tell something
concrete.
tabulated-list is only a generic mode, so maybe it's better when the
implementations add hooks for operations when it makes sense. In any
case, I don't think it's that mode's concern to implement features of
`hi-lock-mode' - which seems to be your intention.
Maybe it would be easier for you to just turn on font-lock-mode. Have
you tried that?
Removing and re-adding pattern highlighting explicitly is only a
workaround. If I would change anything then I would try to improve
hi-lock-mode instead so that it is easier to use under such
circumstances. That `highlight-regexp' does nothing when font-lock-mode
is off (and no automatic highlighting can be assumed) doesn't make much
sense to me. It could just highlight again. But if you think that
further (automatic updating...) you end with a re-implementation of
font-lock-mode in Elisp - thus my suggestion to just try to turn that
mode on.
Michael.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
2022-08-31 0:39 ` Michael Heerdegen
2022-08-31 4:03 ` Jean Louis
2022-08-31 4:19 ` Jean Louis
@ 2022-08-31 21:09 ` Jean Louis
2 siblings, 0 replies; 7+ messages in thread
From: Jean Louis @ 2022-08-31 21:09 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs, larsi, 53771
Here is how I solve it:
(defun rcd-highlight-list (list)
"Highlight LIST of regular expressions in buffer."
(hi-lock-mode)
(let* ((list (delete "" list))
(highlights hi-lock-face-defaults))
(while list
(highlight-regexp (regexp-quote (pop list)) (pop highlights)))))
;; In the following function I am removing values from these two
variables as highlighting does not work otherwise. I consider that
rather a bug.
(defun hyperscope-highlight (&optional highlight-list)
(setq hi-lock-interactive-patterns nil)
(setq hi-lock-interactive-lighters nil)
(let* ((list (hyperscope-action-status-name-list))
(list (append list '("SUCCESS" "DISEASE" "FOLLOW-UP")))
(list (append list highlight-list)))
(rcd-highlight-list list)))
Then I advice tabulated list mode functions.
;;; Advice functions
(defun hyperscope-after-sort (&rest args)
(hyperscope-highlight))
(advice-add 'tabulated-list-col-sort :after 'hyperscope-after-sort)
(advice-add 'tabulated-list-sort :after 'hyperscope-after-sort)
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-09-02 0:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-30 21:11 Why M-x highlight-regexp does not work after sort in tabulated-list-mode? Jean Louis
2022-08-31 0:39 ` Michael Heerdegen
2022-08-31 4:03 ` Jean Louis
2022-08-31 4:19 ` Jean Louis
2022-08-31 4:29 ` Jean Louis
2022-09-02 0:11 ` bug#53771: " Michael Heerdegen
2022-08-31 21:09 ` Jean Louis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).