From 532ccb8dd40348bfcd8c73341e9517570d9563d0 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Jul 2022 23:07:33 -0500 Subject: Add hide-cursor-mode --- lisp/hide-cursor-mode.el | 116 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 lisp/hide-cursor-mode.el (limited to 'lisp') 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 @@ +;;; hide-cursor-mode.el --- Hide the cursor and scroll-lock -*- lexical-binding: t; -*- + +;;; Commentary: + +;; From Karthik: https://karthinks.com/software/more-less-emacs/ + +;;; Code: + +(defvar-local hide-cursor--original nil) + +(progn + (progn :autoload-end + (defvar-local hide-cursor-mode nil "Non-nil if Hide-Cursor mode is enabled. +Use the command `hide-cursor-mode' to change this variable.")) + (defun hide-cursor-mode + (&optional arg) + "Hide or show the cursor. + +This is a minor mode. If called interactively, toggle the +`Hide-Cursor mode' mode. If the prefix argument is positive, +enable the mode, and if it is zero or negative, disable the mode. + +If called from Lisp, toggle the mode if ARG is `toggle'. Enable +the mode if ARG is nil, omitted, or is a positive number. +Disable the mode if ARG is a negative number. + +To check whether the minor mode is enabled in the current buffer, +evaluate `hide-cursor-mode'. + +The mode's hook is called both when the mode is enabled and when +it is disabled. + +When the cursor is hidden `scroll-lock-mode' is enabled, so that +the buffer works like a pager." + (interactive + (list + (if current-prefix-arg + (prefix-numeric-value current-prefix-arg) + 'toggle))) + (let + ((last-message + (current-message))) + (setq hide-cursor-mode + (cond + ((eq arg 'toggle) + (not hide-cursor-mode)) + ((and + (numberp arg) + (< arg 1)) + nil) + (t t))) + (when + (boundp 'local-minor-modes) + (setq local-minor-modes + (delq 'hide-cursor-mode local-minor-modes)) + (when hide-cursor-mode + (push 'hide-cursor-mode local-minor-modes))) + (if hide-cursor-mode + (progn + (scroll-lock-mode 1) + (setq-local hide-cursor--original cursor-type) + (setq-local cursor-type nil)) + (scroll-lock-mode -1) + (setq-local cursor-type + (or hide-cursor--original t))) + (run-hooks 'hide-cursor-mode-hook + (if hide-cursor-mode 'hide-cursor-mode-on-hook 'hide-cursor-mode-off-hook)) + (if + (called-interactively-p 'any) + (progn nil + (unless + (and + (current-message) + (not + (equal last-message + (current-message)))) + (let + ((local " in current buffer")) + (message "Hide-Cursor mode %sabled%s" + (if hide-cursor-mode "en" "dis") + local)))))) + (force-mode-line-update) + hide-cursor-mode) + :autoload-end + (defvar hide-cursor-mode-hook nil) + (unless + (get 'hide-cursor-mode-hook 'variable-documentation) + (put 'hide-cursor-mode-hook 'variable-documentation "Hook run after entering or leaving `hide-cursor-mode'. +No problems result if this variable is not bound. +`add-hook' automatically binds it. (This is true for all hook variables.)")) + (put 'hide-cursor-mode-hook 'custom-type 'hook) + (put 'hide-cursor-mode-hook 'standard-value + (list nil)) + (defvar hide-cursor-mode-map + (let + ((m + (let + ((map + (make-sparse-keymap))) + (define-key map + [f7] + (function hide-cursor-mode)) + map))) + (cond + ((keymapp m) + m) + ((listp m) + (easy-mmode-define-keymap m)) + (t + (error "Invalid keymap %S" m)))) + "Keymap for `hide-cursor-mode'.") + (with-no-warnings + (add-minor-mode 'hide-cursor-mode '"H" hide-cursor-mode-map nil nil))) + +(provide 'hide-cursor-mode) +;;; hide-cursor-mode.el ends here -- cgit 1.4.1-21-gabe81