From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Kevin Vigouroux via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: Adding functionality to a minor mode Date: Tue, 08 Feb 2022 08:41:14 +0100 Message-ID: <874k59rejp.fsf@laposte.net> References: <8735kvtdvh.fsf@ericabrahamsen.net> Reply-To: Kevin Vigouroux 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="28472"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Feb 08 10:21:17 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 1nHMgW-0007CG-UE for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Feb 2022 10:21:17 +0100 Original-Received: from localhost ([::1]:58854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHMgV-0005Qh-Lq for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Feb 2022 04:21:15 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:57022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHL81-0000Y8-Pz for help-gnu-emacs@gnu.org; Tue, 08 Feb 2022 02:41:35 -0500 Original-Received: from smtp-outgoing-1703.laposte.net ([160.92.124.101]:59352) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHL7y-0004YU-7n for help-gnu-emacs@gnu.org; Tue, 08 Feb 2022 02:41:32 -0500 X-mail-filterd: {"version":"1.3.4", "queueID":"4JtFLh1wYRz1GBvt", "contextId":"7e89d590-5cee-476a-b09a-17da0e470e1f"} Original-Received: from outgoing-mail.laposte.net (localhost.localdomain [127.0.0.1]) by mlpnf0114.laposte.net (SMTP Server) with ESMTP id 4JtFLh1wYRz1GBvt for ; Tue, 8 Feb 2022 08:41:16 +0100 (CET) X-mail-filterd: {"version":"1.3.4", "queueID":"4JtFLh07FCz1GBvn", "contextId":"528bd1a2-80b6-4c1b-a3e8-aadb67ea7e61"} X-lpn-mailing: LEGIT X-lpn-spamrating: 50 X-lpn-spamlevel: not-spam X-lpn-spamcause: OK, (0)(0000)gggruggvucftvghtrhhoucdtuddrgedvvddrheeigdduuddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecunfetrffquffvgfdpggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufhffjgfkfgggtgfgsehtqhertddtreejnecuhfhrohhmpefmvghvihhnucggihhgohhurhhouhiguceokhgvrdhvihhgohhurhhouhigsehlrghpohhsthgvrdhnvghtqeenucggtffrrghtthgvrhhnpeekteejteffgeevgeegueegkeefgeekfeegtddtvefhffejgeefkefgfefgkeeltdenucfkphepvddrudegrdefhedrvddvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrddugedrfeehrddvvddtpdhhvghloheprghrrghgohhgpdhmrghilhhfrhhomhepkhgvrdhvihhgohhurhhouhigsehlrghpohhsthgvrdhnvghtpdhnsggprhgtphhtthhopedupdhrtghpthhtohephhgvlhhpqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhgpdhmohguvgepshhmthhpohhuth Original-Received: from aragog (arennes-652-1-305-220.w2-14.abo.wanadoo.fr [2.14.35.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mlpnf0114.laposte.net (SMTP Server) with ESMTPSA id 4JtFLh07FCz1GBvn for ; Tue, 8 Feb 2022 08:41:15 +0100 (CET) Mail-Followup-To: help-gnu-emacs@gnu.org In-Reply-To: (goncholden@protonmail.com's message of "Mon, 07 Feb 2022 13:56:52 +0000") DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=laposte.net; s=lpn-wlmd; t=1644306079; bh=bd6IAKEzb3jiYFvwQfrZiOuDR+aoAUYfodiHZzC8PSc=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; b=EKW84PjeVOwu2n8FGKK/CeEROn0XOHi26P88h9lxrM/FIGQFFL9MWst5sU6Hzu88LYKWzQtR03plny6jNG04zE1knEmmeHxYbpW3yjecJLfWknOF50RsDkO2hO93F/U3ik1rq37uFyxTyTprDRZqAQ6qlZHPJT1JKkCNybThPKEUTxORRiZHzd8iOIerrglNQ9WwyIOwHpB6JkYivv8OAKWUaf9a0vWHl/gYcb09Rw1CNFN4EnDtFJ1EBeoNA48EL3+SrCEUgQZP7h2UNV+Z7ceNFgwY0cqh/PFCf6DcJ/XgE0V/3iHPCZyyIdQIk9E2IZAeL9Dv5kmOe5kA31U9+Q==; Received-SPF: pass client-ip=160.92.124.101; envelope-from=ke.vigouroux@laposte.net; helo=smtp-outgoing-1703.laposte.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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" Xref: news.gmane.io gmane.emacs.help:135824 Archived-At: goncholden writes: > I am also struck about what happens when "(define-minor-mode rich-minor-m= ode" is > used to disable the mode. I suppose that "(when richerenkov-minor-mode" = would > evaluate to false, but the other parts would evaluate. > > Would you be so kind to assist me a little bit, if you please? I get the impression from reading your code, even though I=E2=80=99m a begi= nner, that you want to burn through the steps. > > I normally use ultra-bold, but changed comments to use normal weight and = included the functionality > inside a minor mode like this. With the =E2=80=9Clittle=E2=80=9D knowledge gleaned from the manual, it wou= ld seem to me that things are reversed in your design. =E2=80=A2 Major modes are designed to be customizable using hooks and minor modes. =E2=80=A2 Minor modes are generally independent of a major mode. > > (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. Comments seems to be handled in a major mode using =E2=80=9CFont Lock mode= =E2=80=9D. > > 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)) > I couldn=E2=80=99t explain why but it seems strange: I don=E2=80=99t really= see the point of forming a function just to group functions. > 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)) )) > It seems that you are defining a minor mode when you should be defining a major mode (or derived mode). > ) > > 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)) > --=20 Kevin Vigouroux Best regards