Refactor core initfiles
This commit is contained in:
parent
2a7dac1a4e
commit
8e7cd74e07
8 changed files with 157 additions and 176 deletions
|
@ -1,5 +1,3 @@
|
|||
(provide 'defuns)
|
||||
|
||||
;; Convenience ;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun associate-mode (match mode)
|
||||
(add-to-list 'auto-mode-alist (cons match mode)))
|
||||
|
@ -7,6 +5,30 @@
|
|||
(defun associate-minor-mode (match mode)
|
||||
(add-to-list 'auto-minor-mode-alist (cons match mode)))
|
||||
|
||||
;; Automatic minor modes ;;;;;;;;;;;
|
||||
(defvar auto-minor-mode-alist ()
|
||||
"Alist of filename patterns vs correpsonding minor mode functions,
|
||||
see `auto-mode-alist' All elements of this alist are checked, meaning
|
||||
you can enable multiple minor modes for the same regexp.")
|
||||
(defun enable-minor-mode-based-on-extension ()
|
||||
"check file name against auto-minor-mode-alist to enable minor modes
|
||||
the checking happens for all pairs in auto-minor-mode-alist"
|
||||
(when buffer-file-name
|
||||
(let ((name buffer-file-name)
|
||||
(remote-id (file-remote-p buffer-file-name))
|
||||
(alist auto-minor-mode-alist))
|
||||
;; Remove backup-suffixes from file name.
|
||||
(setq name (file-name-sans-versions name))
|
||||
;; Remove remote file name identification.
|
||||
(when (and (stringp remote-id)
|
||||
(string-match-p (regexp-quote remote-id) name))
|
||||
(setq name (substring name (match-end 0))))
|
||||
(while (and alist (caar alist) (cdar alist))
|
||||
(if (string-match (caar alist) name)
|
||||
(funcall (cdar alist) 1))
|
||||
(setq alist (cdr alist))))))
|
||||
(add-hook 'find-file-hook 'enable-minor-mode-based-on-extension)
|
||||
|
||||
(defmacro λ (&rest body)
|
||||
`(lambda () (interactive) ,@body))
|
||||
|
||||
|
@ -30,6 +52,13 @@
|
|||
'with-no-warnings)
|
||||
(with-eval-after-load ',feature ,@forms)))
|
||||
|
||||
(after "projectile"
|
||||
(defun my--project-root (&optional force-pwd)
|
||||
(if (and (not force-pwd)
|
||||
(projectile-project-p))
|
||||
(projectile-project-root)
|
||||
default-directory)))
|
||||
|
||||
|
||||
;; Keybindings ;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun bind (state &rest keys)
|
||||
|
@ -108,3 +137,6 @@ to abort the minibuffer."
|
|||
(when (get-buffer "*Completions*")
|
||||
(delete-windows-on "*Completions*"))
|
||||
(abort-recursive-edit)))
|
||||
|
||||
|
||||
(provide 'defuns)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue