diff options
author | Case Duckworth | 2022-07-07 23:07:33 -0500 |
---|---|---|
committer | Case Duckworth | 2022-07-07 23:07:33 -0500 |
commit | 532ccb8dd40348bfcd8c73341e9517570d9563d0 (patch) | |
tree | 9ffedaa9806146619a0e297facbbcef1502a7017 | |
parent | Add burly (diff) | |
download | emacs-532ccb8dd40348bfcd8c73341e9517570d9563d0.tar.gz emacs-532ccb8dd40348bfcd8c73341e9517570d9563d0.zip |
Add hide-cursor-mode
-rw-r--r-- | init.el | 25 | ||||
-rw-r--r-- | lisp/hide-cursor-mode.el | 116 |
2 files changed, 141 insertions, 0 deletions
diff --git a/init.el b/init.el index 1b08fe7..e391ecb 100644 --- a/init.el +++ b/init.el | |||
@@ -131,6 +131,31 @@ | |||
131 | (global-goto-address-mode) | 131 | (global-goto-address-mode) |
132 | (add-hook 'after-change-major-mode-hook #'goto-address-mode))) | 132 | (add-hook 'after-change-major-mode-hook #'goto-address-mode))) |
133 | 133 | ||
134 | (setup (:require hide-cursor-mode) ; In lisp/ | ||
135 | (:hook-into view-mode | ||
136 | Info-mode | ||
137 | Man-mode | ||
138 | help-mode | ||
139 | helpful-mode | ||
140 | notmuch-show-mode | ||
141 | magit-log-mode | ||
142 | vc-log-mode | ||
143 | nov-mode | ||
144 | elfeed-show-mode | ||
145 | reading-mode) | ||
146 | (:bind-into (view | ||
147 | Info | ||
148 | help-mode | ||
149 | helpful | ||
150 | notmuch-show | ||
151 | magit-log | ||
152 | nov | ||
153 | elfeed-show | ||
154 | reading) | ||
155 | "<f7>" #'hide-cursor-mode) | ||
156 | (:with-mode Man-mode | ||
157 | (:bind "<f7>" #'hide-cursor-mode))) | ||
158 | |||
134 | (setup (:require pulse) | 159 | (setup (:require pulse) |
135 | (:also-load +pulse) | 160 | (:also-load +pulse) |
136 | (:option pulse-flag nil | 161 | (:option pulse-flag nil |
diff --git a/lisp/hide-cursor-mode.el b/lisp/hide-cursor-mode.el new file mode 100644 index 0000000..6325d81 --- /dev/null +++ b/lisp/hide-cursor-mode.el | |||
@@ -0,0 +1,116 @@ | |||
1 | ;;; hide-cursor-mode.el --- Hide the cursor and scroll-lock -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; From Karthik: https://karthinks.com/software/more-less-emacs/ | ||
6 | |||
7 | ;;; Code: | ||
8 | |||
9 | (defvar-local hide-cursor--original nil) | ||
10 | |||
11 | (progn | ||
12 | (progn :autoload-end | ||
13 | (defvar-local hide-cursor-mode nil "Non-nil if Hide-Cursor mode is enabled. | ||
14 | Use the command `hide-cursor-mode' to change this variable.")) | ||
15 | (defun hide-cursor-mode | ||
16 | (&optional arg) | ||
17 | "Hide or show the cursor. | ||
18 | |||
19 | This is a minor mode. If called interactively, toggle the | ||
20 | `Hide-Cursor mode' mode. If the prefix argument is positive, | ||
21 | enable the mode, and if it is zero or negative, disable the mode. | ||
22 | |||
23 | If called from Lisp, toggle the mode if ARG is `toggle'. Enable | ||
24 | the mode if ARG is nil, omitted, or is a positive number. | ||
25 | Disable the mode if ARG is a negative number. | ||
26 | |||
27 | To check whether the minor mode is enabled in the current buffer, | ||
28 | evaluate `hide-cursor-mode'. | ||
29 | |||
30 | The mode's hook is called both when the mode is enabled and when | ||
31 | it is disabled. | ||
32 | |||
33 | When the cursor is hidden `scroll-lock-mode' is enabled, so that | ||
34 | the buffer works like a pager." | ||
35 | (interactive | ||
36 | (list | ||
37 | (if current-prefix-arg | ||
38 | (prefix-numeric-value current-prefix-arg) | ||
39 | 'toggle))) | ||
40 | (let | ||
41 | ((last-message | ||
42 | (current-message))) | ||
43 | (setq hide-cursor-mode | ||
44 | (cond | ||
45 | ((eq arg 'toggle) | ||
46 | (not hide-cursor-mode)) | ||
47 | ((and | ||
48 | (numberp arg) | ||
49 | (< arg 1)) | ||
50 | nil) | ||
51 | (t t))) | ||
52 | (when | ||
53 | (boundp 'local-minor-modes) | ||
54 | (setq local-minor-modes | ||
55 | (delq 'hide-cursor-mode local-minor-modes)) | ||
56 | (when hide-cursor-mode | ||
57 | (push 'hide-cursor-mode local-minor-modes))) | ||
58 | (if hide-cursor-mode | ||
59 | (progn | ||
60 | (scroll-lock-mode 1) | ||
61 | (setq-local hide-cursor--original cursor-type) | ||
62 | (setq-local cursor-type nil)) | ||
63 | (scroll-lock-mode -1) | ||
64 | (setq-local cursor-type | ||
65 | (or hide-cursor--original t))) | ||
66 | (run-hooks 'hide-cursor-mode-hook | ||
67 | (if hide-cursor-mode 'hide-cursor-mode-on-hook 'hide-cursor-mode-off-hook)) | ||
68 | (if | ||
69 | (called-interactively-p 'any) | ||
70 | (progn nil | ||
71 | (unless | ||
72 | (and | ||
73 | (current-message) | ||
74 | (not | ||
75 | (equal last-message | ||
76 | (current-message)))) | ||
77 | (let | ||
78 | ((local " in current buffer")) | ||
79 | (message "Hide-Cursor mode %sabled%s" | ||
80 | (if hide-cursor-mode "en" "dis") | ||
81 | local)))))) | ||
82 | (force-mode-line-update) | ||
83 | hide-cursor-mode) | ||
84 | :autoload-end | ||
85 | (defvar hide-cursor-mode-hook nil) | ||
86 | (unless | ||
87 | (get 'hide-cursor-mode-hook 'variable-documentation) | ||
88 | (put 'hide-cursor-mode-hook 'variable-documentation "Hook run after entering or leaving `hide-cursor-mode'. | ||
89 | No problems result if this variable is not bound. | ||
90 | `add-hook' automatically binds it. (This is true for all hook variables.)")) | ||
91 | (put 'hide-cursor-mode-hook 'custom-type 'hook) | ||
92 | (put 'hide-cursor-mode-hook 'standard-value | ||
93 | (list nil)) | ||
94 | (defvar hide-cursor-mode-map | ||
95 | (let | ||
96 | ((m | ||
97 | (let | ||
98 | ((map | ||
99 | (make-sparse-keymap))) | ||
100 | (define-key map | ||
101 | [f7] | ||
102 | (function hide-cursor-mode)) | ||
103 | map))) | ||
104 | (cond | ||
105 | ((keymapp m) | ||
106 | m) | ||
107 | ((listp m) | ||
108 | (easy-mmode-define-keymap m)) | ||
109 | (t | ||
110 | (error "Invalid keymap %S" m)))) | ||
111 | "Keymap for `hide-cursor-mode'.") | ||
112 | (with-no-warnings | ||
113 | (add-minor-mode 'hide-cursor-mode '"H" hide-cursor-mode-map nil nil))) | ||
114 | |||
115 | (provide 'hide-cursor-mode) | ||
116 | ;;; hide-cursor-mode.el ends here | ||