From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.help Subject: Major-mode devel: how to drop font-lock 'display when mode is disabled? Date: Mon, 11 Mar 2024 09:41:56 +0300 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19912"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.50.4 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 11 07:43:06 2024 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 1rjZNK-0004wQ-9U for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 11 Mar 2024 07:43:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjZMQ-0002ps-3u; Mon, 11 Mar 2024 02:42:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjZMO-0002pU-8H for help-gnu-emacs@gnu.org; Mon, 11 Mar 2024 02:42:08 -0400 Original-Received: from forward102a.mail.yandex.net ([178.154.239.85]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjZML-0000Mi-97 for help-gnu-emacs@gnu.org; Mon, 11 Mar 2024 02:42:08 -0400 Original-Received: from mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net [IPv6:2a02:6b8:c0d:2a02:0:640:77d9:0]) by forward102a.mail.yandex.net (Yandex) with ESMTPS id 04228608FC for ; Mon, 11 Mar 2024 09:41:57 +0300 (MSK) Original-Received: by mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ufeIO4YRu0U0-VWu03w1t; Mon, 11 Mar 2024 09:41:56 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1710139316; bh=pU7nz9+fXxFUQd25iE9uKUBoUBwOVzQKRsmZ3W6FmFg=; h=Date:To:From:Subject:Message-ID; b=iIfAxzCJmxvdbgi6z7LBQGYGNy32wwsb9G+vTLbWa6mZ5lHuJCyBh2qpSjQ+a8Squ nRqYePbai5PKf8BcnOhxuRitgqiuySQeW4te4H0K1/qHT2ldQJaFyyXu0y32WJoTgG khZ23U3WKlEPL3cGjIxCSXBwYQBckdSDuIbYWtAY= Authentication-Results: mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Received-SPF: pass client-ip=178.154.239.85; envelope-from=Hi-Angel@yandex.ru; helo=forward102a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:146069 Archived-At: (please keep me CC'ed) Someone on emacs.stackexchange wanted a mode to display timestamps in `.zsh_history` file in a human-redable form=C2=B9. After some searching and experimentation I figured it's easy by making a major mode, which basically uses a `(put-text-property start end 'display human-redable-text)` to change the display of timestamps. It works fine but one problem I couldn't figure out how to get rid of is that upon changing the major mode the custom display does not go away. I've had very hard time finding any documentation or posts that would explain how's that supposed to work. My gut feeling is that when I call `(font-lock-add-keywords)` with the mode name as 2-nd arg, that allows font-lock to associate display changes to the mode name and thus remove them once the mode disappears. But it doesn't work for me that way. As a workaround I have the following call: (add-to-list 'font-lock-extra-managed-props 'display) =E2=80=A6however, I presume this will make all "display" changes disappear, even if they been done by another mode, which isn't good. For reference, the code from my answer on emacs.stackexchange is below: ;;; --- zsh_history highlighting -*- lexical-binding: t -*- (defvar zsh-hist-display-date-format "%a %d %b %Y %T %Z" "Date format for displaying the timestamp (see `man date')") (defun zsh-hist-convert-unix-timestamp (timestamp) (format-time-string zsh-hist-display-date-format (seconds-to-time (string-to-number timestamp)))) (defun zsh-hist-display () (let ((start (match-beginning 0)) (end (match-end 0))) (put-text-property start end 'display (zsh-hist-convert-unix-timestamp (match-string-n= o-properties 1))) ;; put some highlighting (put-text-property start end 'face '(:weight bold)) (put-text-property start end 'zsh-hist:fontified t) nil)) (define-derived-mode zsh-history-mode text-mode "Zsh History Files" "Major mode for viewing zsh-history files." (add-to-list 'font-lock-extra-managed-props 'zsh-hist:fontified) ;; BUG: this may potentially remove font-lock for other modes that de= cided to use ;; 'display. Unfortunately it is unclear how to make font-lock only r= emove 'display ;; for our mode. (add-to-list 'font-lock-extra-managed-props 'display) (font-lock-add-keywords 'zsh-history-mode '(("^: \\([0-9]+\\)" (0 (zs= h-hist-display)))))) ;;;###autoload (add-to-list 'auto-mode-alist '("zsh_history" . zsh-history-mode)) 1: https://emacs.stackexchange.com/q/80674/2671#view-timestamps-in-human-re= adable-format