From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Shahid Newsgroups: gmane.emacs.bugs Subject: bug#10754: define-minor-mode and doc of derived mode Date: Fri, 08 Jun 2018 21:45:03 +0000 Message-ID: <87in6trm00.fsf@gmail.com> References: <87po12g7x4.fsf@gmail.com> <0edf0759-1044-4c6f-b70a-addebc9078f8@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1528494251 23208 195.159.176.226 (8 Jun 2018 21:44:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 8 Jun 2018 21:44:11 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: 10754@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 08 23:44:07 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fRPAx-0005pM-Km for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Jun 2018 23:44:03 +0200 Original-Received: from localhost ([::1]:38280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRPD4-0004ft-Ek for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Jun 2018 17:46:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRPCw-0004fj-TU for bug-gnu-emacs@gnu.org; Fri, 08 Jun 2018 17:46:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRPCr-0005gP-WD for bug-gnu-emacs@gnu.org; Fri, 08 Jun 2018 17:46:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60445) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRPCr-0005gJ-QO for bug-gnu-emacs@gnu.org; Fri, 08 Jun 2018 17:46:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fRPCr-0003jf-Jv for bug-gnu-emacs@gnu.org; Fri, 08 Jun 2018 17:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: John Shahid Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 Jun 2018 21:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10754 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10754-submit@debbugs.gnu.org id=B10754.152849431714306 (code B ref 10754); Fri, 08 Jun 2018 21:46:01 +0000 Original-Received: (at 10754) by debbugs.gnu.org; 8 Jun 2018 21:45:17 +0000 Original-Received: from localhost ([127.0.0.1]:40109 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fRPC9-0003ig-1B for submit@debbugs.gnu.org; Fri, 08 Jun 2018 17:45:17 -0400 Original-Received: from mail-qt0-f176.google.com ([209.85.216.176]:37066) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fRPC7-0003iT-7v for 10754@debbugs.gnu.org; Fri, 08 Jun 2018 17:45:15 -0400 Original-Received: by mail-qt0-f176.google.com with SMTP id q13-v6so14929770qtp.4 for <10754@debbugs.gnu.org>; Fri, 08 Jun 2018 14:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=9BOqVuUUBcUvE33pH9lQspYJQ/VmUHGw+0b+G9JcuJk=; b=nRLzBDp0VOD8D2Arl4zNbbaXTjFjD4YTdETkWHyQCRv6nonN/9AEK1neoSIFLxwEC0 1uU0tuSODEHQZ51aorCPkuxWJ7EAwpXQpIbS1LF+yiE4LGTBWvo3TwFIQ1XcNuvMwlYD opTWadd0O5UmNAfOgPrc5RBuAJmCOJnYw7MuEStc05gHokIYioTlZG8SBE8Cw1qtJpJk hSABUkz6d5wd4jKFOmgYzXMy3AF6Z47nYkMC+6RseMKnLArZT9R7iYB1lsbfJpBifX32 iZVcvd1WrFosfkG3B2+kZfJ+a+y3rTidft2YvQEFoHMYbEex1ZVzKFmyloCvb9tRPDiE 0izg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=9BOqVuUUBcUvE33pH9lQspYJQ/VmUHGw+0b+G9JcuJk=; b=tnu9YpJ/N8Azk0QH7D4JCs5hHvQ8JpAX6SA0xDQIzycVa3jusJLHv6KUZ9CXWuCQsQ j3qD6RrDHmP9lPTcRhyyVlR+NvGTuuKJhMDmvsxU/sRSH5bakwuBPmK8uhO8FvqsmdL5 gGpHcnApKw8KufBfCAzqTE+KU3Yz/OQuBmw980fkIiInx7E8YtGkgDnpoyLlFoQM8iTb tL8kqbIjbxZAVbfV6LhFUsPGpvhtTJFl0KTfOqyVhqpwc/nbfALjH/SphysnKbguYhye HZh+3yeFRwPf8G3cL6NTQYrEOcB8bnY6xgf5g4DZVygnCirWSqL4p1/wLV1JXzxYZmGn C7+A== X-Gm-Message-State: APt69E38sa6lYWilqu09IUL37GpSiMfTdOzutiP6oOot4pSiP88WWr9d jEYbwUsjjdZerDlqAT2JrMbPzhp8 X-Google-Smtp-Source: ADUXVKKgHqRh4X+MNocTpxyvqaD+eOLarXjG5TDvPg3S/+GPjMUxh/vxjV+eW59T+pc3xZfvwMJtWQ== X-Received: by 2002:a0c:8a29:: with SMTP id 38-v6mr5004584qvt.75.1528494309280; Fri, 08 Jun 2018 14:45:09 -0700 (PDT) Original-Received: from 14be7a43aff7 (cpe-184-152-55-93.nyc.res.rr.com. [184.152.55.93]) by smtp.gmail.com with ESMTPSA id u1-v6sm6698669qkd.45.2018.06.08.14.45.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jun 2018 14:45:08 -0700 (PDT) In-reply-to: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147210 Archived-At: --=-=-= Content-Type: text/plain attached a poc patch. wdyt ? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-allow-interpolation-of-arg-in-define-minor-mode-DOC.patch >From 1a1efd1417356d26dd818622497512c28005f03c Mon Sep 17 00:00:00 2001 From: John Shahid Date: Tue, 5 Jun 2018 19:56:12 -0400 Subject: [PATCH] allow interpolation of %{arg} in define-minor-mode DOC * easy-mmode.el (define-minor-mode): interpolate %{arg} in DOC with documentation of the mode argument * linum.el (linum-mode): use %{arg} in the docstring --- lisp/emacs-lisp/easy-mmode.el | 28 +++++++++++++++++++++------- lisp/linum.el | 4 +--- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index a81b6fefb2..8d5dd39ea3 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -81,6 +81,23 @@ easy-mmode-pretty-mode-name ;; space.) (replace-regexp-in-string (regexp-quote lighter) lighter name t t)))) +(defconst easy-mmode-arg-docstring + "With a prefix argument ARG, enable %s if ARG is positive, and +disable it otherwise. If called from Lisp, enable the mode if +ARG is omitted or nil, and toggle it if ARG is `toggle'. Disable +the mode otherwise") + +(defun easy-mmode-mode-docstring (doc mode-pretty-name keymap-sym) + (let ((doc (or doc + (format "Toggle %s on or off. +%%{arg}. +\\{%s}" mode-pretty-name keymap-sym)))) + (replace-regexp-in-string "%{arg}" + (format easy-mmode-arg-docstring + mode-pretty-name + mode-pretty-name) + doc))) + ;;;###autoload (defalias 'easy-mmode-define-minor-mode 'define-minor-mode) ;;;###autoload @@ -101,7 +118,9 @@ define-minor-mode if the argument is omitted or nil or a positive integer). If DOC is nil, give the mode command a basic doc-string -documenting what its argument does. +documenting what its argument does. All occurences of the string +\"%{arg}\" in DOC will be replaced by a docstring explaining +usages of the mode argument. Optional INIT-VALUE is the initial value of the mode's variable. Optional LIGHTER is displayed in the mode line when the mode is on. @@ -270,12 +289,7 @@ define-minor-mode ;; The actual function. (defun ,modefun (&optional arg ,@extra-args) - ,(or doc - (format (concat "Toggle %s on or off. -With a prefix argument ARG, enable %s if ARG is -positive, and disable it otherwise. If called from Lisp, enable -the mode if ARG is omitted or nil, and toggle it if ARG is `toggle'. -\\{%s}") pretty-name pretty-name keymap-sym)) + ,(easy-mmode-mode-docstring doc pretty-name keymap-sym) ;; Use `toggle' rather than (if ,mode 0 1) so that using ;; repeat-command still does the toggling correctly. (interactive (list (or current-prefix-arg 'toggle))) diff --git a/lisp/linum.el b/lisp/linum.el index 9df0c5d023..6a0baf40a6 100644 --- a/lisp/linum.el +++ b/lisp/linum.el @@ -75,9 +75,7 @@ linum-delay ;;;###autoload (define-minor-mode linum-mode "Toggle display of line numbers in the left margin (Linum mode). -With a prefix argument ARG, enable Linum mode if ARG is positive, -and disable it otherwise. If called from Lisp, enable the mode -if ARG is omitted or nil. +%{arg}. Linum mode is a buffer-local minor mode." :lighter "" ; for desktop.el -- 2.17.1 --=-=-=--