-
Notifications
You must be signed in to change notification settings - Fork 4
/
bool-flip.el
63 lines (52 loc) · 1.53 KB
/
bool-flip.el
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
;;; bool-flip.el --- flip the boolean under the point
;; Copyright (C) 2016 Michael Brandt
;;
;; Author: Michael Brandt <[email protected]>
;; URL: http://github.com/michaeljb/bool-flip/
;; Package-Requires: ((emacs "24.3"))
;; Version: 1.0.1
;; Keywords: boolean, convenience, usability
;; This file is not part of GNU Emacs.
;;; License:
;; Licensed under the same terms as Emacs.
;;; Commentary:
;; Bind the following commands:
;; bool-flip-do-flip
;;
;; For a detailed introduction see:
;; http://github.com/michaeljb/bool-flip/blob/master/README.md
;;; Code:
(require 'cl-lib)
(defcustom bool-flip-alist
'(("T" . "F")
("t" . "f")
("TRUE" . "FALSE")
("True" . "False")
("true" . "false")
("Y" . "N")
("y" . "n")
("YES" . "NO")
("Yes" . "No")
("yes" . "no")
("1" . "0"))
"List of values flipped by `bool-flip-do-flip'."
:group 'bool-flip
:safe 'listp)
;;;###autoload
(defun bool-flip-do-flip ()
"Replace the boolean at point with its opposite."
(interactive)
(let* ((old (thing-at-point 'symbol))
(new (or (cdr (assoc old bool-flip-alist))
(car (rassoc old bool-flip-alist)))))
(if new
(cl-destructuring-bind (beg . end)
(bounds-of-thing-at-point 'symbol)
(let ((insert-after (= (point) beg)))
(delete-region beg end)
(insert new)
(when insert-after
(goto-char beg))))
(user-error "Nothing to flip here"))))
(provide 'bool-flip)
;;; bool-flip.el ends here