mirror of
https://github.com/vale981/boon
synced 2025-03-06 01:51:38 -05:00
clean core
This commit is contained in:
parent
c185846fbd
commit
e601e602c8
2 changed files with 45 additions and 37 deletions
62
boon-core.el
62
boon-core.el
|
@ -5,6 +5,7 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(require 'face-remap)
|
(require 'face-remap)
|
||||||
|
(require 'cl-macs)
|
||||||
;; Maps
|
;; Maps
|
||||||
|
|
||||||
(defvar boon-x-map (make-sparse-keymap))
|
(defvar boon-x-map (make-sparse-keymap))
|
||||||
|
@ -67,34 +68,33 @@
|
||||||
(t (message "Unknown state!")))
|
(t (message "Unknown state!")))
|
||||||
(force-mode-line-update))
|
(force-mode-line-update))
|
||||||
|
|
||||||
(defun boon-set-insert-state ()
|
|
||||||
(interactive) (boon-set-state 'boon-insert-state))
|
|
||||||
|
|
||||||
(defun boon-set-insert-like-state ()
|
(defun boon-set-insert-like-state ()
|
||||||
|
"Switch to off or insert state, depending on mode."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (special-mode-p) (boon-set-off-state) (boon-set-insert-state)))
|
(if (boon-special-mode-p) (boon-set-off-state) (boon-set-state 'boon-insert-state)))
|
||||||
|
|
||||||
(defun boon-set-command-state ()
|
(defun boon-set-command-state ()
|
||||||
"Switch to command state and push a mark to remember the last edition point."
|
"Switch to command state and push a mark to remember the last edition point."
|
||||||
(interactive) (boon-set-state 'boon-command-state))
|
(interactive) (boon-set-state 'boon-command-state))
|
||||||
|
|
||||||
(defun boon-set-off-state ()
|
(defun boon-set-off-state ()
|
||||||
|
"Switch to off state."
|
||||||
(interactive) (boon-set-state 'boon-off-state))
|
(interactive) (boon-set-state 'boon-off-state))
|
||||||
|
|
||||||
(defun boon-helm-set-insert-state ()
|
(defun boon-helm-set-insert-state ()
|
||||||
|
"Switch to insert state in an helm minibuffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(setq boon-helm-command-state nil)
|
(setq boon-helm-command-state nil)
|
||||||
(setq cursor-type 'bar))
|
(setq cursor-type 'bar))
|
||||||
|
|
||||||
(defun boon-helm-set-command-state ()
|
(defun boon-helm-set-command-state ()
|
||||||
|
"Switch to command state in an helm minibuffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(setq boon-helm-command-state t)
|
(setq boon-helm-command-state t)
|
||||||
(setq cursor-type 'box))
|
(setq cursor-type 'box))
|
||||||
|
|
||||||
|
(defvar boon-special-mode-list
|
||||||
;;; Initialisation and activation
|
'(Buffer-menu-mode
|
||||||
(defun special-mode-p ()
|
|
||||||
(memq major-mode '(Buffer-menu-mode
|
|
||||||
Custom-mode
|
Custom-mode
|
||||||
completion-list-mode
|
completion-list-mode
|
||||||
debugger-mode
|
debugger-mode
|
||||||
|
@ -103,7 +103,15 @@
|
||||||
magit-branch-manager-mode
|
magit-branch-manager-mode
|
||||||
git-rebase-mode
|
git-rebase-mode
|
||||||
magit-log-mode
|
magit-log-mode
|
||||||
magit-status-mode)))
|
magit-status-mode)
|
||||||
|
"List of modes which start in boon-off-state."
|
||||||
|
)
|
||||||
|
|
||||||
|
(defun boon-special-mode-p ()
|
||||||
|
"Is the major mode in boon-special-mode-list?"
|
||||||
|
(memq major-mode boon-special-mode-list))
|
||||||
|
|
||||||
|
;;; Initialisation and activation
|
||||||
|
|
||||||
(define-minor-mode boon-local-mode
|
(define-minor-mode boon-local-mode
|
||||||
"Minor mode for setting up command mode in a single buffer."
|
"Minor mode for setting up command mode in a single buffer."
|
||||||
|
@ -119,14 +127,13 @@
|
||||||
;; the major-mode in a buffer changes. This preliminary
|
;; the major-mode in a buffer changes. This preliminary
|
||||||
;; initialization is only for the case when `boon-local-mode' is
|
;; initialization is only for the case when `boon-local-mode' is
|
||||||
;; called directly for the first time in a buffer.
|
;; called directly for the first time in a buffer.
|
||||||
(set (make-local-variable 'boon-regexp) nil)
|
|
||||||
(cond
|
(cond
|
||||||
((special-mode-p)
|
((boon-special-mode-p)
|
||||||
(boon-set-off-state))
|
(boon-set-off-state))
|
||||||
((memq major-mode '(magit-commit-mode
|
((memq major-mode '(magit-commit-mode
|
||||||
git-commit-mode
|
git-commit-mode
|
||||||
))
|
))
|
||||||
(boon-set-insert-state))
|
(boon-set-insert-like-state))
|
||||||
(t (boon-set-command-state))))
|
(t (boon-set-command-state))))
|
||||||
(t
|
(t
|
||||||
(boon-set-off-state)
|
(boon-set-off-state)
|
||||||
|
@ -135,40 +142,41 @@
|
||||||
|
|
||||||
(add-hook 'minibuffer-setup-hook 'boon-minibuf-hook)
|
(add-hook 'minibuffer-setup-hook 'boon-minibuf-hook)
|
||||||
|
|
||||||
(defun eq-if-bound (sym val)
|
|
||||||
(and (boundp sym) (eq (eval sym) val)))
|
|
||||||
|
|
||||||
(defun boon-minibuf-hook ()
|
(defun boon-minibuf-hook ()
|
||||||
"Detect if the minibuffer is a helm minibuffer, and activate boon helm command mode if so."
|
"Detect if the minibuffer is a helm minibuffer, and activate boon helm command mode if so."
|
||||||
|
(cl-flet ((eq-if-bound (sym val) (and (boundp sym) (eq (eval sym) val))))
|
||||||
(cond
|
(cond
|
||||||
((eq-if-bound 'helm-map (current-local-map))
|
((eq-if-bound 'helm-map (current-local-map))
|
||||||
(boon-helm-set-command-state))
|
(boon-helm-set-command-state))
|
||||||
((eq-if-bound 'helm-git-grep-map (current-local-map))
|
((eq-if-bound 'helm-git-grep-map (current-local-map))
|
||||||
(boon-helm-set-command-state))
|
(boon-helm-set-command-state))
|
||||||
(t (setq cursor-type 'bar))))
|
(t (setq cursor-type 'bar)))))
|
||||||
|
|
||||||
(defun boon-initialize ()
|
|
||||||
"Enable Boon in the current buffer, if appropriate. To enable Boon globally, do (boon-mode 1)."
|
|
||||||
(unless (minibufferp)
|
|
||||||
(boon-local-mode 1)))
|
|
||||||
|
|
||||||
(define-globalized-minor-mode boon-mode
|
|
||||||
boon-local-mode boon-initialize)
|
|
||||||
|
|
||||||
;; The function `boon-initialize' should only be used to initialize
|
;; The function `boon-initialize' should only be used to initialize
|
||||||
;; `boon-local-mode' from the globalized minor-mode `boon-mode'. It is
|
;; `boon-local-mode' from the globalized minor-mode `boon-mode'. It is
|
||||||
;; called whenever boon is enabled in a buffer for the first time or
|
;; called whenever boon is enabled in a buffer for the first time or
|
||||||
;; when boon is active and the major-mode of the buffer changes.
|
;; when boon is active and the major-mode of the buffer changes.
|
||||||
|
(defun boon-initialize ()
|
||||||
|
"Enable Boon in the current buffer, if appropriate. To enable Boon globally, do (boon-mode 1)."
|
||||||
|
(unless (minibufferp)
|
||||||
|
(boon-local-mode 1)))
|
||||||
|
|
||||||
(defun turn-on-boon-mode (&optional arg)
|
;;;###autoload (autoload 'boon-mode "boon" "Toggle boon in all buffers" t)
|
||||||
|
(define-globalized-minor-mode boon-mode
|
||||||
|
boon-local-mode boon-initialize)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun turn-on-boon-mode ()
|
||||||
"Turn on Boon in the current buffer."
|
"Turn on Boon in the current buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(boon-local-mode (or arg 1)))
|
(boon-local-mode 1))
|
||||||
|
|
||||||
(defun turn-off-boon-mode (&optional arg)
|
;;;###autoload
|
||||||
|
(defun turn-off-boon-mode ()
|
||||||
"Turn off Boon in the current buffer."
|
"Turn off Boon in the current buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(boon-local-mode (or arg -1)))
|
(boon-local-mode -1))
|
||||||
|
|
||||||
(defun boon-modeline-string ()
|
(defun boon-modeline-string ()
|
||||||
"Return a string describing the current state."
|
"Return a string describing the current state."
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
(unless (eq (following-char) 32)
|
(unless (eq (following-char) 32)
|
||||||
(insert (make-string 1 32))
|
(insert (make-string 1 32))
|
||||||
(backward-char 1))
|
(backward-char 1))
|
||||||
(boon-set-insert-state))
|
(boon-set-insert-like-state))
|
||||||
|
|
||||||
(defun boon-split-line ()
|
(defun boon-split-line ()
|
||||||
"split the current line"
|
"split the current line"
|
||||||
|
|
Loading…
Add table
Reference in a new issue