unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* avoid global variables by using closures
@ 2021-09-08 20:07 Emanuel Berg via Users list for the GNU Emacs text editor
  2021-09-08 20:58 ` Jude DaShiell
  0 siblings, 1 reply; 3+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-09-08 20:07 UTC (permalink / raw)
  To: help-gnu-emacs

I don't know what I've been smoking, this gave me a warning
from the byte-compiler saying the function wasn't known to be
defined, but now it seems to work all of a sudden?

(require 'cl-lib)

(let ((times 0))
  (defun time (&optional reset)
    (interactive)
    (let ((res (or reset current-prefix-arg)))
      (if res
          (setq times 0)
        (cl-incf times) ))
    (if (called-interactively-p 'interactive)
        (message "times: %d" times)
      times) ))
;; test:
;;   (call-interactively 'time)
;;   (let ((current-prefix-arg t)) (call-interactively 'time))
;;   (time)
;;   (time t)

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2021-09-08 22:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-08 20:07 avoid global variables by using closures Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-08 20:58 ` Jude DaShiell
2021-09-08 22:05   ` Emanuel Berg via Users list for the GNU Emacs text editor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).