From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: goncholden Newsgroups: gmane.emacs.help Subject: Re: Adding functionality to a minor mode Date: Mon, 07 Feb 2022 13:56:52 +0000 Message-ID: References: <8735kvtdvh.fsf@ericabrahamsen.net> Reply-To: goncholden 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="6539"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Eric Abrahamsen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 07 15:42:43 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 1nH5E2-0001Sk-OA for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 15:42:42 +0100 Original-Received: from localhost ([::1]:44936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH5E1-0007Wn-O3 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 09:42:41 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH4Vn-0003Fu-JJ for help-gnu-emacs@gnu.org; Mon, 07 Feb 2022 08:56:59 -0500 Original-Received: from mail-4318.protonmail.ch ([185.70.43.18]:35871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH4Vk-0000kk-49 for help-gnu-emacs@gnu.org; Mon, 07 Feb 2022 08:56:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail2; t=1644242213; bh=uS4LRhIkIEgmbUaAo1yM4TfcrBDEFCqnMxrrvvuTA4Q=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc; b=Mul2G8prqOp+88PJHlf6OVKDyH/4ZvZEhDoN3ASvQJ9fXkv6XdRPROnH5UVOgm7dB S4vmRDhUcg89xXXQT/6QuvXJhHP/65qJ/xnBv15/XOFjuTMxxMysHAI+F6YzxylNbY 5WlSufUoEKpdoPRwDYdtSMtlSJt5H4CurT/G4Srs3WzjPbiOewRVqEO2hBZTZHMv8d fCLNo490rSAgylqyFmMU5sisoxjJG7pM1JUMdo177DVg7/3MncZBvCVMdPhHlUFtFn aNKD0V9/GFn8lQl6bJQQY+gfhNQypUQPtqRHWrp7/zeMpy2I9GVPunTTeUC2IKlQIm PowNr6VqSQblw== In-Reply-To: <8735kvtdvh.fsf@ericabrahamsen.net> Received-SPF: pass client-ip=185.70.43.18; envelope-from=goncholden@protonmail.com; helo=mail-4318.protonmail.ch 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, SPF_HELO_PASS=-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" Xref: news.gmane.io gmane.emacs.help:135797 Archived-At: ------- Original Message ------- On Monday, February 7th, 2022 at 6:00 AM, Eric Abrahamsen wrote: > goncholden goncholden@protonmail.com writes: > > > ------ Original Message ------- > > > > On Saturday, February 5th, 2022 at 6:50 PM, goncholden goncholden@proto= nmail.com wrote: > > > ------- Original Message ------- > > > On Saturday, February 5th, 2022 at 10:00 AM, goncholden via Users > > > list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote: > > > > > > > I have made a minor-mode with some defvar and defun. Have added som= e functionality > > > > for comments, and put everything in the following function definiti= on. > > > > > > > > (defun rich-annotation-tools () > > > > "Aggregates annotation tools for comments." > > > > (rich-annotation-font-weight) > > > > (rich-annotation-low-contrast) > > > > (rich-annotation-keytrigger)) > > > > > > > > I would expect to add "(rich-annotation-tools)" in > > > > define-minor-mode. Would I introduce it > > > > within the "(when rich-minor-mode" part? > > > > > > > > ;;;###autoload > > > > > > > > (define-minor-mode rich-minor-mode > > > > > > > > "This is the description." > > > > :lighter "rich" ; indicator in mode-line > > > > (font-lock-remove-keywords nil rich-font-lock) > > > > > > > > (when rich-minor-mode > > > > (font-lock-add-keywords nil rich-font-lock 'append) > > > > (set (make-local-variable 'jit-lock-contextually) t) ) > > > > (rich-annotation-tools) > > > > > > > > (with-no-warnings (font-lock-fontify-buffer)) )) ) > > > > Could I get some clarification for using "(when rich-minor-mode" and wh= en not to? > > What's happening here is that, when you define a minor mode, it also > defines a variable of the same name, which can be tested as a boolean to > see if the minor mode is currently enabled or not. > > The only thing you need to know is that, when the minor mode is turned > on or off, the variable is set before the body is run. So if you test > the boolean variable in the body code of the minor mode, it will be t if > you've just turned the mode on, and nil if you've just turned it off. > > For some reason, when I first started playing with minor modes, this > struck me as backwards. I can no longer say why, exactly, but I remember > it did. I am also struck about what happens when "(define-minor-mode rich-minor-mod= e" is used to disable the mode. I suppose that "(when richerenkov-minor-mode" wo= uld evaluate to false, but the other parts would evaluate. Would you be so kind to assist me a little bit, if you please? I normally use ultra-bold, but changed comments to use normal weight and in= cluded the functionality inside a minor mode like this. (defun rich-annotation-font-weight () "Makes normal font weight for comments." (set-face-attribute 'font-lock-comment-face nil :weight 'normal)) Is there a way that I can remember the :weight used initially, "(set-face-attribute 'default nil :height 160 :weight 'ultra-bold)" so I can set comments to ultra-bold again when the minor-mode is disabled. Then I added some additional functionality and put it here (defun rich-annotation-tools () "Aggregates annotation tools for comments." (rich-annotation-font-weight) (rich-annotation-low-contrast) (rich-annotation-keytrigger)) Here is my definition of the minor-mode ;;;###autoload (define-minor-mode rich-minor-mode "Colour Brace Marks according to their depth." :lighter "rich" ; indicator in mode-line (font-lock-remove-keywords nil rich-font-lock) (when rich-minor-mode (font-lock-add-keywords nil rich-font-lock 'append) (set (make-local-variable 'jit-lock-contextually) t) ) (rich-annotation-tools) (when font-lock-mode (if (fboundp 'font-lock-flush) (font-lock-flush) (with-no-warnings (font-lock-fontify-buffer)) )) ) Would it be better to introduce (rich-annotation-tools) in the "(when rich-minor-mode" part or outside it. To enable and disable the minor-mode, I have added ;;;###autoload (defun rich-minor-mode-enable () "Enable `rich-minor-mode'." (rich-minor-mode 1)) ;;;###autoload (defun rich-minor-mode-disable () "Disable `rich-minor-mode'." (rich-minor-mode 0))