all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#44341: 27.1; define-minor-mode generates inaccurate docstring
@ 2020-10-31 11:00 Thibault Polge
  2020-11-01 14:00 ` Lars Ingebrigtsen
  2020-11-01 15:29 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Thibault Polge @ 2020-10-31 11:00 UTC (permalink / raw)
  To: 44341

[-- Attachment #1: Type: text/plain, Size: 2282 bytes --]

In my Emacs 27.1, the following line:

(define-minor-mode test-mode "A test.")

generates a function test-mode whose docstring ends as follows:

> If called from Lisp, also enable the mode if ARG is omitted or nil,
> and toggle it if ARG is ‘toggle’; disable the mode otherwise.

This case (non-interactively, enable the mode if ARG is non-nil, unless
it's toggle) doesn't seem to have been implemented.  Here's a test that
demonstrates that:

(mapcar
  (lambda (x) (test-mode x) (cons x test-mode))
  '(t ; Should disable.
    nil ; Should disable
    -33 ; Should NOT disable (but will)
    33 ; Should enable
    0 ; Should disable
    toggle ; Should toggle, and will.
    toggle ; Repeated for confirmation
    disable ; Should disable (as a random symbol)
    disable ; Again
    "What?" ; Same.
    ))

The generated function reads as follows, and indeed implements none of
the conditions the docstring describes.  The relevant par is in the
first half, before (run-hooks)

(defun test-mode
    (&optional arg)
  "A test.\n\nIf called interactively, enable Test mode if ARG is positive, and\ndisable it if ARG is zero or negative.  If called from Lisp, also\nenable the mode if ARG is omitted or nil, and toggle it if ARG is\n`toggle'; disable the mode otherwise."
  (interactive
   (list
    (or current-prefix-arg 'toggle)))
  (let
      ((last-message
        (current-message)))
    (setq test-mode
          (if
              (eq arg 'toggle)
              (not test-mode)
            (>
             (prefix-numeric-value arg)
             0)))
    (run-hooks 'test-mode-hook
               (if test-mode 'test-mode-on-hook 'test-mode-off-hook))
    (if
        (called-interactively-p 'any)
        (progn nil
               (unless
                   (and
                    (current-message)
                    (not
                     (equal last-message
                            (current-message))))
                 (let
                     ((local " in current buffer"))
                   (message "Test mode %sabled%s"
                            (if test-mode "en" "dis")
                            local))))))
  (force-mode-line-update)
  test-mode)

Best regards,
Thibault

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 857 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-11-02 16:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-31 11:00 bug#44341: 27.1; define-minor-mode generates inaccurate docstring Thibault Polge
2020-11-01 14:00 ` Lars Ingebrigtsen
2020-11-01 15:29 ` Stefan Monnier
2020-11-02 12:28   ` Philipp Stephani
2020-11-02 15:35     ` Lars Ingebrigtsen
2020-11-02 15:52     ` Eli Zaretskii
2020-11-02 16:18     ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.