aboutsummaryrefslogtreecommitdiff
path: root/meen.el
blob: 627db1cc8efc541cdd2d6b072c51ea4b40d42151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;;; meen.el --- Hide clocks replacing them with fish -*- lexical-binding: t -*-

;; Hide clocks replacing them with fish
;; Copyright (C) 2022 Arun Isaac
;;
;; Author: Arun Isaac <arunisaac@systemreboot.net>
;; Version: 0.1.0
;; Homepage: https://git.systemreboot.net/meen
;; Package-Requires: ((emacs "25.1"))

;; This file is part of meen.

;; meen 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.

;; meen 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 meen.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; meen is a minor mode to hide clocks replacing them with fish icons.
;; It is useful to escape the tyranny of the clock and live a life not
;; knowing the precise artificial time.
;;
;; Usage:
;;
;; Toggle meen mode in all buffers using M-x global-meen-mode. Or,
;; toggle meen mode in the current buffer using M-x meen-mode.
;;
;; Clocks will be replaced by Unicode fish icons. You will need a font
;; that supports the Unicode fish icon. If you would rather use some
;; other character, customize `meen-char'.

;;; Code:

(defcustom meen-regexp
  (rx (repeat 1 2 digit) ":" (= 2 digit) (optional ":" (= 2 digit)))
  "Regexp matching clocks to hide.")

(defcustom meen-regexp-group
  0
  "Regexp group in `meen-regexp' to hide.")

(defcustom meen-char
  ?🐟
  "Character to hide clock with.")

(defun meen-compose ()
  "Compose matching region in the current buffer."
  (compose-region (match-beginning meen-regexp-group)
                  (match-end meen-regexp-group)
                  meen-char))

;;;###autoload
(define-minor-mode meen-mode
  "Meen mode."
  :lighter " meen"
  (let ((keywords `((,meen-regexp
                     (,meen-regexp-group
                      (meen-compose))))))
    (if meen-mode
        ;; Enable mode.
        (font-lock-add-keywords nil keywords)
      ;; Disable mode.
      (font-lock-remove-keywords nil keywords)
      (with-silent-modifications
        (remove-text-properties (point-min)
                                (point-max)
                                '(composition nil))))
    (font-lock-flush)))

(defun meen-turn-on ()
  "Enable `meen-mode' in the current buffer if it is not already."
  (unless meen-mode
    (meen-mode)))

;;;###autoload
(define-globalized-minor-mode global-meen-mode
  meen-mode meen-turn-on)

(provide 'meen)

;;; meen.el ends here