bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#44341: 27.1; define-minor-mode generates inaccurate docstring


From: Thibault Polge
Subject: bug#44341: 27.1; define-minor-mode generates inaccurate docstring
Date: Sat, 31 Oct 2020 12:00:23 +0100

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: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]