├── README.md └── bool-flip.el /README.md: -------------------------------------------------------------------------------- 1 | ## Bool-flip 2 | 3 | Bool-flip is a simple utility to quickly change the boolean value under the 4 | point. For example, it changes "true" to "false", and vice versa. 5 | 6 | ## Installation 7 | 8 | Install via [MELPA](https://melpa.org/). 9 | 10 | ## Usage 11 | 12 | Add these lines to your `.emacs` file: 13 | 14 | ``` 15 | (require 'bool-flip) 16 | (global-set-key (kbd "C-c b") 'bool-flip-do-flip) 17 | ``` 18 | 19 | ## Changelog 20 | 21 | ### 1.0.1 22 | 23 | * Fix yes/no pair (was 24 | yes/yes). Thanks 25 | [@nixmaniack](https://github.com/nixmaniack). ([#5](https://github.com/michaeljb/bool-flip/pull/5)) 26 | * Documentation 27 | fix. Thanks 28 | [@solkaz](https://github.com/solkaz). ([#4](https://github.com/michaeljb/bool-flip/pull/4)) 29 | 30 | ### 1.0.0 31 | * Initial release. 32 | * Basic true/false and yes/no pairs, as well as 1/0. 33 | -------------------------------------------------------------------------------- /bool-flip.el: -------------------------------------------------------------------------------- 1 | ;;; bool-flip.el --- flip the boolean under the point 2 | 3 | ;; Copyright (C) 2016 Michael Brandt 4 | ;; 5 | ;; Author: Michael Brandt 6 | ;; URL: http://github.com/michaeljb/bool-flip/ 7 | ;; Package-Requires: ((emacs "24.3")) 8 | ;; Version: 1.0.1 9 | ;; Keywords: boolean, convenience, usability 10 | 11 | ;; This file is not part of GNU Emacs. 12 | 13 | ;;; License: 14 | 15 | ;; Licensed under the same terms as Emacs. 16 | 17 | ;;; Commentary: 18 | 19 | ;; Bind the following commands: 20 | ;; bool-flip-do-flip 21 | ;; 22 | ;; For a detailed introduction see: 23 | ;; http://github.com/michaeljb/bool-flip/blob/master/README.md 24 | 25 | ;;; Code: 26 | 27 | (require 'cl-lib) 28 | 29 | (defcustom bool-flip-alist 30 | '(("T" . "F") 31 | ("t" . "f") 32 | ("TRUE" . "FALSE") 33 | ("True" . "False") 34 | ("true" . "false") 35 | ("Y" . "N") 36 | ("y" . "n") 37 | ("YES" . "NO") 38 | ("Yes" . "No") 39 | ("yes" . "no") 40 | ("1" . "0")) 41 | "List of values flipped by `bool-flip-do-flip'." 42 | :group 'bool-flip 43 | :safe 'listp) 44 | 45 | ;;;###autoload 46 | (defun bool-flip-do-flip () 47 | "Replace the boolean at point with its opposite." 48 | (interactive) 49 | (let* ((old (thing-at-point 'symbol)) 50 | (new (or (cdr (assoc old bool-flip-alist)) 51 | (car (rassoc old bool-flip-alist))))) 52 | (if new 53 | (cl-destructuring-bind (beg . end) 54 | (bounds-of-thing-at-point 'symbol) 55 | (let ((insert-after (= (point) beg))) 56 | (delete-region beg end) 57 | (insert new) 58 | (when insert-after 59 | (goto-char beg)))) 60 | (user-error "Nothing to flip here")))) 61 | 62 | (provide 'bool-flip) 63 | ;;; bool-flip.el ends here 64 | --------------------------------------------------------------------------------