summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2022-07-07 23:07:33 -0500
committerCase Duckworth2022-07-07 23:07:33 -0500
commit532ccb8dd40348bfcd8c73341e9517570d9563d0 (patch)
tree9ffedaa9806146619a0e297facbbcef1502a7017 /lisp
parentAdd burly (diff)
downloademacs-532ccb8dd40348bfcd8c73341e9517570d9563d0.tar.gz
emacs-532ccb8dd40348bfcd8c73341e9517570d9563d0.zip
Add hide-cursor-mode
Diffstat (limited to 'lisp')
-rw-r--r--lisp/hide-cursor-mode.el116
1 files changed, 116 insertions, 0 deletions
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.
14Use the command `hide-cursor-mode' to change this variable."))
15 (defun hide-cursor-mode
16 (&optional arg)
17 "Hide or show the cursor.
18
19This is a minor mode. If called interactively, toggle the
20`Hide-Cursor mode' mode. If the prefix argument is positive,
21enable the mode, and if it is zero or negative, disable the mode.
22
23If called from Lisp, toggle the mode if ARG is `toggle'. Enable
24the mode if ARG is nil, omitted, or is a positive number.
25Disable the mode if ARG is a negative number.
26
27To check whether the minor mode is enabled in the current buffer,
28evaluate `hide-cursor-mode'.
29
30The mode's hook is called both when the mode is enabled and when
31it is disabled.
32
33When the cursor is hidden `scroll-lock-mode' is enabled, so that
34the 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'.
89No 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