all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org, larsi@gnu.org, 53771@debbugs.gnu.org
Subject: Re: Why M-x highlight-regexp does not work after sort in tabulated-list-mode?
Date: Wed, 31 Aug 2022 07:19:04 +0300	[thread overview]
Message-ID: <Yw7hOCgaYrqSs59J@protected.localdomain> (raw)
In-Reply-To: <871qsxnt57.fsf@web.de>

* 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/



  parent reply	other threads:[~2022-08-31  4:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-08-31  4:29     ` Jean Louis
2022-09-02  0:11     ` bug#53771: " Michael Heerdegen
2022-08-31 21:09   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yw7hOCgaYrqSs59J@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=53771@debbugs.gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=larsi@gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.