summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--count.el161
-rw-r--r--durand-align.el61
-rw-r--r--input-conf.el25
-rw-r--r--modeline.el31
-rw-r--r--org-conf.el4
-rw-r--r--tex-conf.el1
6 files changed, 282 insertions, 1 deletions
diff --git a/count.el b/count.el
new file mode 100644
index 0000000..0be7b82
--- /dev/null
+++ b/count.el
@@ -0,0 +1,161 @@
+;;; count.el --- Easy counting facility -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Jean Sévère Durand
+
+;; Author: Jean Sévère Durand <durand@jsdurand.xyz>
+;; Keywords: emulations, games
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Counting mode
+
+;;; 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 \
+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)
+ (set 'cursor-type nil))
+
+(let ((map count-mode-map))
+ (define-key map (vector 'up) #'count-up)
+ (define-key map (vector 'down) #'count-down)
+ (define-key map (vector ?r) #'count-refresh)
+ (define-key map (vector ?o) #'count-reset)
+ (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."
+ (interactive)
+ (let ((buffer (get-buffer-create counting-buffer-name)))
+ (with-current-buffer buffer
+ (count-mode))
+ (switch-to-buffer buffer)))
+
+;;;; Count in a new buffer always
+
+(defun count-start ()
+ "Start counting in a new buffer."
+ (interactive)
+ (let* ((name (generate-new-buffer-name counting-buffer-name))
+ (buffer (get-buffer-create name)))
+ (with-current-buffer buffer
+ (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 font-size scales
+ (expt
+ text-scale-mode-step
+ counting-font-step)))
+ (space-width (string-pixel-width (string #x20)))
+ (padding (/ (- (window-pixel-width) (* 2 space-width)
+ number-str-width)
+ 2.0))
+ (height (window-body-height nil 'remap))
+ (half (floor height 2)))
+ (concat
+ (make-string half #xa)
+ (propertize
+ (string #x20)
+ 'display (list 'space :width (list padding)))
+ number-str)))
+
+(defun count-refresh ()
+ "Refresh the counting buffer."
+ (interactive)
+ (cond
+ ((derived-mode-p 'count-mode)
+ (let ((inhibit-read-only t))
+ (setq text-scale-mode-amount counting-font-step)
+ (text-scale-mode 1)
+ (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"))))
+
+(defun count-up (&optional arg)
+ "Increase the count by ARG."
+ (interactive "P")
+ (setq arg (cond ((null arg) 1) ((prefix-numeric-value arg))))
+ (setq count-mode-value (+ arg count-mode-value))
+ (count-refresh))
+
+(defun count-down (&optional arg)
+ "Decrease the count by ARG."
+ (interactive "P")
+ (setq arg (cond ((null arg) 1) ((prefix-numeric-value arg))))
+ (setq count-mode-value (- count-mode-value arg))
+ (count-refresh))
+
+(defun count-reset ()
+ "Reset `count-mode-value' to zero."
+ (interactive)
+ (setq count-mode-value 0)
+ (count-refresh))
+
+(defun count-enlarge (&optional arg)
+ "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))))
+ (setq counting-font-step (+ counting-font-step arg))
+ (count-refresh))
+
+(defun count-shrink (&optional arg)
+ "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))))
+ (setq counting-font-step (- counting-font-step arg))
+ (count-refresh))
+
+(provide 'count)
+;;; count.el ends here
diff --git a/durand-align.el b/durand-align.el
new file mode 100644
index 0000000..079f421
--- /dev/null
+++ b/durand-align.el
@@ -0,0 +1,61 @@
+;;; durand-align.el --- Pixel alignment -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Jean Sévère Durand
+
+;; Author: Jean Sévère Durand <durand@jsdurand.xyz>
+;; Keywords: wp, faces
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Some little functions to center buffer texts at pixel level
+;; precision.
+
+;;; Code:
+
+(defun durand-center (&optional pixels)
+ "Center the buffer.
+If PIXELS is not-nil, use that as body width in pixels."
+ (let* ((body-width (cond ((and pixels (numberp pixels) (> pixels 0))
+ pixels)
+ ((car (window-text-pixel-size
+ nil
+ (cons (window-start) 0)
+ (window-end))))))
+ (len (floor (- (window-body-width nil t) body-width) 2))
+ (prop (list 'space :width (list len)))
+ (str (propertize (string 32) 'display prop 'durand-center t)))
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (cond
+ ((get-text-property (point) 'durand-center)
+ (put-text-property (point) (1+ (point)) 'display prop))
+ ((insert str)))
+ (forward-line 1)))))
+
+(defun durand-cancel-center ()
+ "Cancel the inserted characters."
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (cond
+ ((get-text-property (point) 'durand-center)
+ (delete-char 1)))
+ (forward-line 1))))
+
+
+(provide 'durand-align)
+;;; durand-align.el ends here
diff --git a/input-conf.el b/input-conf.el
index 986286a..a735741 100644
--- a/input-conf.el
+++ b/input-conf.el
@@ -37,5 +37,30 @@
(setq-default default-input-method "devanagari-kyoto-harvard")
+(defvar durand-input-method-list nil
+ "The list of input methods that I oft use.")
+
+(setq durand-input-method-list
+ (list "devanagari-kyoto-harvard"
+ "tamil99"
+ "chinese-zozy"))
+
+(defun durand-toggle-input ()
+ "Toggle input method with my customizations."
+ (interactive)
+ (cond
+ ((null current-input-method)
+ (let ((input-method
+ (minibuffer-with-setup-hook
+ #'durand-headlong-minibuffer-setup-hook
+ (completing-read
+ "Input method: " durand-input-method-list
+ nil t nil nil "devanagari-kyoto-harvard"))))
+ (activate-input-method input-method)))
+ ((deactivate-input-method))))
+
+(define-key global-map (vector ?\C-\\) #'durand-toggle-input)
+(define-key global-map (vector 3 ?i) #'durand-toggle-input)
+
(provide 'input-conf)
;;; input-conf.el ends here
diff --git a/modeline.el b/modeline.el
index ee2c0fd..09ef407 100644
--- a/modeline.el
+++ b/modeline.el
@@ -90,6 +90,35 @@
(format-mode-line global-mode-string face)))))
;;;###autoload
+(defun modeline-format-gnus ()
+ "The mode line format for GNUS."
+ (let* ((left (modeline-gnus-format-left))
+ (right (string-trim-right (modeline-format-right)))
+ (left-len (string-pixel-width left))
+ (right-len (string-pixel-width right))
+ (middle (propertize
+ (string 32)
+ 'display
+ (list
+ 'space
+ :width
+ (list
+ (- (window-pixel-width) left-len right-len
+ (- modeline-right-offset)))))))
+ (concat left middle right)))
+
+(defun modeline-gnus-format-left ()
+ "The left part of the mode line for GNUS."
+ (declare (side-effect-free t) (pure t))
+ (concat
+ (modeline-spc)
+ (modeline-format-buffer-name)
+ (modeline-spc)
+ (modeline-format-keycast)
+ (modeline-spc)
+ (modeline-format-minor-modes)))
+
+;;;###autoload
(defun modeline-format-left ()
"The left mode line format."
(concat
@@ -578,7 +607,7 @@ string in the mode line.")
('mode-line-inactive))))
(concat
(modeline-propertize
- (format-mode-line '("%m") face)
+ (format-mode-line (list mode-name) face)
nil
"Major mode\nmouse-1: Display major mode menu\nmouse-2:\
Show help for major mode\nmouse-3: Toggle minor modes"
diff --git a/org-conf.el b/org-conf.el
index 6f00728..6287658 100644
--- a/org-conf.el
+++ b/org-conf.el
@@ -277,6 +277,10 @@ in Lisp code use `org-set-tags' instead."
:empty-lines 1
:kill-buffer t
:immediate-finish t)
+ ("e" "Store electric degrees" entry
+ (file+headline "/Users/durand/org/notes.org" "विद्युद्देयकः")
+ "* %? - %<%Y-%m-%d %H:%M:%S %Z>\n"
+ :jump-to-captured t)
("t" "TODO" entry
(file "~/org/aujourdhui.org")
"* TODO %? %^{Date to do:}t\n :PROPERTIES:\n :RECORD_TIME: %U\n :END:\n\n"
diff --git a/tex-conf.el b/tex-conf.el
index f1b9029..eb8f0c5 100644
--- a/tex-conf.el
+++ b/tex-conf.el
@@ -297,6 +297,7 @@ where the macro part is without the backslash.")
(cons "o" "circ")
(list "{" "{" "}")
(list "(" "(" ")")
+ (list "[" "[" "]")
(list "<" "langle" "rangle")
(list "b" "lvert" "rvert")))