[Top][All Lists]

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

Re: Why M-x highlight-regexp does not work after sort in tabulated-list-

From: Jean Louis
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
User-agent: Mutt/+ () (2022-06-11)

* Michael Heerdegen <> [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.
        (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-print t))
    ;; Sort based on a column name.
    (let ((name (if n
                    (car (aref tabulated-list-format n))
                  (get-text-property (point)
      (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-print t)

    (hyperscope-highlight) ;; My function


Take action in Free Software Foundation campaigns:

In support of Richard M. Stallman

reply via email to

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