From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help 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 Message-ID: References: <871qsxnt57.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33707"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-06-11) Cc: help-gnu-emacs@gnu.org, larsi@gnu.org, 53771@debbugs.gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 31 06:20:46 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTFDa-0008aa-9U for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 31 Aug 2022 06:20:46 +0200 Original-Received: from localhost ([::1]:37246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTFDY-0008Dk-KE for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 31 Aug 2022 00:20:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTFCU-0008DM-6n for help-gnu-emacs@gnu.org; Wed, 31 Aug 2022 00:19:38 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:58499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTFCS-0004E1-89; Wed, 31 Aug 2022 00:19:37 -0400 Original-Received: from localhost ([::ffff:197.239.4.74]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000B5AF4.00000000630EE152.00006825; Tue, 30 Aug 2022 21:19:29 -0700 Mail-Followup-To: Michael Heerdegen , help-gnu-emacs@gnu.org, larsi@gnu.org, 53771@debbugs.gnu.org Content-Disposition: inline In-Reply-To: <871qsxnt57.fsf@web.de> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SBL=0.141, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:139191 Archived-At: * 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. (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/