diff options
author | JSDurand <mmemmew@gmail.com> | 2025-01-01 11:28:54 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2025-01-01 11:28:54 +0800 |
commit | f625d194fbac2e31f2d932863479586ffb0045dc (patch) | |
tree | 82188a0bf4b84b25f2f28920f0d4c2440562a4db | |
parent | 2a7c0e542a0bdba9aa0df4618357f60932bffcf2 (diff) |
Documentation styles and error message conventions.
-rw-r--r-- | count.el | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -24,16 +24,26 @@ ;;; Code: +;;; Variables + +;;;; Buffer name + (defvar counting-buffer-name "*Count*" "The name of the buffer within which to count.") +;;;; Font-scaling factor + (defvar counting-font-step 10 - "The proportion by which the counting value font size is + "The proportion by which the counting value font size is \ increased.") +;;;; Counted value + (defvar-local count-mode-value 0 "The value of the current count.") +;;; Major mode + (define-derived-mode count-mode special-mode "Count" "Major mode for counting." (count-refresh) @@ -47,6 +57,9 @@ increased.") (define-key map (vector ?=) #'count-enlarge) (define-key map (vector ?-) #'count-shrink)) +;;; Functions to start counting + +;;;; Count in an old buffer if possible (defun count-start-or-switch () "Start counting in an old buffer if possible." @@ -56,6 +69,8 @@ increased.") (count-mode)) (switch-to-buffer buffer))) +;;;; Count in a new buffer always + (defun count-start () "Start counting in a new buffer." (interactive) @@ -65,12 +80,18 @@ increased.") (count-mode)) (switch-to-buffer buffer))) +;;; Auxiliary functions + +;;;; Format the counted value + +(defvar text-scale-mode-step) + (defun count-make-pad-string (number) "Make a padding string that centers the NUMBER." (declare (pure t) (side-effect-free t)) (let* ((number-str (format "%d" number)) (number-str-width (* (string-pixel-width number-str) - ;; account for the remapping + ;; account for the font-size scales (expt text-scale-mode-step counting-font-step))) @@ -98,7 +119,7 @@ increased.") (delete-region (point-min) (point-max)) (insert (count-make-pad-string count-mode-value)))) ((user-error - "This function needs to be in the count-mode.")))) + "This function needs to be in the count-mode")))) (defun count-up (&optional arg) "Increase the count by ARG." @@ -121,7 +142,7 @@ increased.") (count-refresh)) (defun count-enlarge (&optional arg) - "Increase the font size by ARG steps. + "Increase the font size by ARG many times. The size of one step is defined by `text-scale-mode-step'." (interactive "p") (setq arg (cond ((null arg) 1) ((prefix-numeric-value arg)))) @@ -129,7 +150,7 @@ The size of one step is defined by `text-scale-mode-step'." (count-refresh)) (defun count-shrink (&optional arg) - "Decrease the font size by ARG steps. + "Decrease the font size by ARG many times. The size of one step is defined by `text-scale-mode-step'." (interactive "p") (setq arg (cond ((null arg) 1) ((prefix-numeric-value arg)))) |