1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-10 15:56:18 +00:00

* lisp/type-break.el: Use lexical-binding.

(type-break-mode): Use define-minor-mode.
This commit is contained in:
Stefan Monnier 2012-09-28 11:17:08 -04:00
parent 404043ea88
commit 3df749b0f8
2 changed files with 58 additions and 79 deletions

View File

@ -1,5 +1,8 @@
2012-09-28 Stefan Monnier <monnier@iro.umontreal.ca>
* type-break.el: Use lexical-binding.
(type-break-mode): Use define-minor-mode.
* emacs-lisp/pcase.el (pcase--mark-used): New.
(pcase--u1): Use it (bug#12512).

View File

@ -1,4 +1,4 @@
;;; type-break.el --- encourage rests from typing at appropriate intervals
;;; type-break.el --- encourage rests from typing at appropriate intervals -*- lexical-binding: t -*-
;; Copyright (C) 1994-1995, 1997, 2000-2012 Free Software Foundation, Inc.
@ -69,18 +69,6 @@
:prefix "type-break"
:group 'keyboard)
(defcustom type-break-mode nil
"Toggle typing break mode.
See the docstring for the `type-break-mode' command for more information.
Setting this variable directly does not take effect;
use either \\[customize] or the function `type-break-mode'."
:set (lambda (_symbol value)
(type-break-mode (if value 1 -1)))
:initialize 'custom-initialize-default
:type 'boolean
:group 'type-break
:require 'type-break)
(defcustom type-break-interval (* 60 60)
"Number of seconds between scheduled typing breaks."
:type 'integer
@ -285,7 +273,7 @@ It will be either \"seconds\" or \"keystrokes\".")
;;;###autoload
(defun type-break-mode (&optional prefix)
(define-minor-mode type-break-mode
"Enable or disable typing-break mode.
This is a minor mode, but it is global to all buffers by default.
@ -358,74 +346,61 @@ Finally, a file (named `type-break-file-name') is used to store information
across Emacs sessions. This provides recovery of the break status between
sessions and after a crash. Manual changes to the file may result in
problems."
(interactive "P")
:lighter type-break-mode-line-format
:global t
(type-break-check-post-command-hook)
(let ((already-enabled type-break-mode))
(setq type-break-mode (>= (prefix-numeric-value prefix) 0))
(cond
;; ((and already-enabled type-break-mode)
;; (and (called-interactively-p 'interactive)
;; (message "Type Break mode is already enabled")))
(type-break-mode
(when type-break-file-name
(with-current-buffer (find-file-noselect type-break-file-name 'nowarn)
(setq buffer-save-without-query t)))
(cond
((and already-enabled type-break-mode)
(and (called-interactively-p 'interactive)
(message "Type Break mode is already enabled")))
(type-break-mode
(when type-break-file-name
(with-current-buffer (find-file-noselect type-break-file-name 'nowarn)
(setq buffer-save-without-query t)))
(or global-mode-string (setq global-mode-string '(""))) ;FIXME: Why?
(type-break-keystroke-reset)
(type-break-mode-line-countdown-or-break nil)
(or global-mode-string
(setq global-mode-string '("")))
(or (assq 'type-break-mode-line-message-mode
minor-mode-alist)
(setq minor-mode-alist
(cons type-break-mode-line-format
minor-mode-alist)))
(type-break-keystroke-reset)
(type-break-mode-line-countdown-or-break nil)
(setq type-break-time-last-break
(or (type-break-get-previous-time)
(current-time)))
(setq type-break-time-last-break
(or (type-break-get-previous-time)
(current-time)))
;; schedule according to break time from session file
(type-break-schedule
(let (diff)
(if (and type-break-time-last-break
(< (setq diff (type-break-time-difference
type-break-time-last-break
(current-time)))
type-break-interval))
;; use the file's value
(progn
(setq type-break-keystroke-count
(type-break-get-previous-count))
;; file the time, in case it was read from the auto-save file
(type-break-file-time type-break-interval-start)
(setq type-break-interval-start type-break-time-last-break)
(- type-break-interval diff))
;; schedule from now
(setq type-break-interval-start (current-time))
(type-break-file-time type-break-interval-start)
type-break-interval))
type-break-interval-start
type-break-interval)
(and (called-interactively-p 'interactive)
(message "Type Break mode is enabled and set")))
(t
(type-break-keystroke-reset)
(type-break-mode-line-countdown-or-break nil)
(type-break-cancel-schedule)
(do-auto-save)
(when type-break-file-name
(with-current-buffer (find-file-noselect type-break-file-name
'nowarn)
(set-buffer-modified-p nil)
(unlock-buffer)
(kill-this-buffer)))
(and (called-interactively-p 'interactive)
(message "Type Break mode is disabled")))))
type-break-mode)
;; Schedule according to break time from session file.
(type-break-schedule
(let (diff)
(if (and type-break-time-last-break
(< (setq diff (type-break-time-difference
type-break-time-last-break
(current-time)))
type-break-interval))
;; Use the file's value.
(progn
(setq type-break-keystroke-count
(type-break-get-previous-count))
;; File the time, in case it was read from the auto-save file.
(type-break-file-time type-break-interval-start)
(setq type-break-interval-start type-break-time-last-break)
(- type-break-interval diff))
;; Schedule from now.
(setq type-break-interval-start (current-time))
(type-break-file-time type-break-interval-start)
type-break-interval))
type-break-interval-start
type-break-interval))
(t
(type-break-keystroke-reset)
(type-break-mode-line-countdown-or-break nil)
(type-break-cancel-schedule)
(do-auto-save)
(when type-break-file-name
(with-current-buffer (find-file-noselect type-break-file-name
'nowarn)
(set-buffer-modified-p nil)
(unlock-buffer)
(kill-this-buffer))))))
(define-minor-mode type-break-mode-line-message-mode
"Toggle warnings about typing breaks in the mode line.
@ -994,10 +969,11 @@ FRAC should be the inverse of the fractional value; for example, a value of
;; "low" bits and format the time incorrectly.
(defun type-break-time-sum (&rest tmlist)
(let ((sum '(0 0 0)))
(dolist (tem tmlist sum)
(dolist (tem tmlist)
(setq sum (time-add sum (if (integerp tem)
(list (floor tem 65536) (mod tem 65536))
tem))))))
tem))))
sum))
(defun type-break-time-stamp (&optional when)
(if (fboundp 'format-time-string)