General clean up

This commit is contained in:
Henrik Lissner 2016-05-20 09:23:46 -04:00
parent 3ff02c51ef
commit bf858508c6
6 changed files with 180 additions and 184 deletions

View file

@ -74,7 +74,7 @@
;; Local settings ;; Local settings
(load "~/.emacs.local.el" t t) (load "~/.emacs.local.el" t t)
(setq narf-current-theme (if (display-graphic-p) narf-default-theme narf-terminal-theme) (setq narf-current-theme (if (display-graphic-p) narf-default-theme narf-terminal-theme)
narf-current-font narf-default-font) narf-current-font narf-default-font)
;; Here we a'go! ;; Here we a'go!
(mapc 'require packages) (mapc 'require packages)

View file

@ -74,10 +74,8 @@
"Close popups, disable search highlights and quit the minibuffer if open." "Close popups, disable search highlights and quit the minibuffer if open."
(let ((minib-p (minibuffer-window-active-p (minibuffer-window))) (let ((minib-p (minibuffer-window-active-p (minibuffer-window)))
(evil-hl-p (evil-ex-hl-active-p 'evil-ex-search))) (evil-hl-p (evil-ex-hl-active-p 'evil-ex-search)))
(when minib-p (when minib-p (abort-recursive-edit))
(abort-recursive-edit)) (when evil-hl-p (evil-ex-nohighlight))
(when evil-hl-p
(evil-ex-nohighlight))
;; Close non-repl popups and clean up `narf-popup-windows' ;; Close non-repl popups and clean up `narf-popup-windows'
(unless (or minib-p evil-hl-p (unless (or minib-p evil-hl-p
(memq (get-buffer-window) narf-popup-windows)) (memq (get-buffer-window) narf-popup-windows))

View file

@ -73,179 +73,178 @@
(add-hook 'shackle-popup-hook 'narf|hide-mode-line) ; No mode line in popups (add-hook 'shackle-popup-hook 'narf|hide-mode-line) ; No mode line in popups
;; Prevents popups from messaging with windows-moving functions ;; Prevents popups from messaging with windows-moving functions
(after! defuns-popup (defun narf*save-popups (orig-fun &rest args)
(defun narf*save-popups (orig-fun &rest args) (narf/popup-save (apply orig-fun args)))
(narf/popup-save (apply orig-fun args))) (advice-add 'narf/evil-window-move :around 'narf*save-popups))
(advice-add 'narf--evil-window-move :around 'narf*save-popups)
(advice-add 'narf--evil-swap-windows :around 'narf*save-popups))
;;
;; Hacks
;;
(after! help-mode ;;
;; So that help buffer links do not open in the help popup, we need to redefine these ;; Hacks
;; three button types to use `switch-to-buffer-other-window' rather than ;;
;; `pop-to-buffer'. Instead of lambas these help-functions should be function symbols,
;; so that we could advise those instead of clumsify redefine these button types.
(define-button-type 'help-function-def
:supertype 'help-xref
'help-function (lambda (fun file)
(require 'find-func)
(when (eq file 'C-source)
(setq file (help-C-file-name (indirect-function fun) 'fun)))
(let ((location
(find-function-search-for-symbol fun nil file)))
(switch-to-buffer-other-window (car location))
(if (cdr location)
(goto-char (cdr location))
(message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find function's definition"))
(define-button-type 'help-variable-def (after! help-mode
:supertype 'help-xref ;; So that help buffer links do not open in the help popup, we need to redefine these
'help-function (lambda (var &optional file) ;; three button types to use `switch-to-buffer-other-window' rather than
(when (eq file 'C-source) ;; `pop-to-buffer'. Instead of lambas these help-functions should be function symbols,
(setq file (help-C-file-name var 'var))) ;; so that we could advise those instead of clumsify redefine these button types.
(let ((location (find-variable-noselect var file))) (define-button-type 'help-function-def
(switch-to-buffer-other-window (car location)) :supertype 'help-xref
(if (cdr location) 'help-function (lambda (fun file)
(goto-char (cdr location)) (require 'find-func)
(message "Unable to find location in file")))) (when (eq file 'C-source)
'help-echo (purecopy "mouse-2, RET: find variable's definition")) (setq file (help-C-file-name (indirect-function fun) 'fun)))
(let ((location
(find-function-search-for-symbol fun nil file)))
(switch-to-buffer-other-window (car location))
(if (cdr location)
(goto-char (cdr location))
(message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find function's definition"))
(define-button-type 'help-face-def (define-button-type 'help-variable-def
:supertype 'help-xref :supertype 'help-xref
'help-function (lambda (fun file) 'help-function (lambda (var &optional file)
(require 'find-func) (when (eq file 'C-source)
(let ((location (setq file (help-C-file-name var 'var)))
(find-function-search-for-symbol fun 'defface file))) (let ((location (find-variable-noselect var file)))
(switch-to-buffer-other-window (car location)) (switch-to-buffer-other-window (car location))
(if (cdr location) (if (cdr location)
(goto-char (cdr location)) (goto-char (cdr location))
(message "Unable to find location in file")))) (message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find face's definition"))) 'help-echo (purecopy "mouse-2, RET: find variable's definition"))
(after! helm (define-button-type 'help-face-def
;; This is a good alternative to either popwin or shackle, specifically for helm. If :supertype 'help-xref
;; either fail me (for the last time), this is where I'll turn. 'help-function (lambda (fun file)
;;(add-to-list 'display-buffer-alist (require 'find-func)
;; `(,(rx bos "*helm" (* not-newline) "*" eos) (let ((location
;; (display-buffer-in-side-window) (find-function-search-for-symbol fun 'defface file)))
;; (inhibit-same-window . t) (switch-to-buffer-other-window (car location))
;; (window-height . 0.4))) (if (cdr location)
(goto-char (cdr location))
(message "Unable to find location in file"))))
'help-echo (purecopy "mouse-2, RET: find face's definition")))
;; Helm tries to clean up after itself, but shackle has already done this. This fixes (after! helm
;; that. To reproduce, add a helm rule in `shackle-rules', open two splits ;; This is a good alternative to either popwin or shackle, specifically for helm. If
;; side-by-side, move to the buffer on the right and invoke helm. It will close all ;; either fail me (for the last time), this is where I'll turn.
;; but the left-most buffer. ;;(add-to-list 'display-buffer-alist
(setq-default helm-reuse-last-window-split-state t ;; `(,(rx bos "*helm" (* not-newline) "*" eos)
helm-split-window-in-side-p t)) ;; (display-buffer-in-side-window)
;; (inhibit-same-window . t)
;; (window-height . 0.4)))
(after! helm-swoop ;; Helm tries to clean up after itself, but shackle has already done this. This fixes
(setq helm-swoop-split-window-function (lambda ($buf) (narf/popup-buffer $buf)))) ;; that. To reproduce, add a helm rule in `shackle-rules', open two splits
;; side-by-side, move to the buffer on the right and invoke helm. It will close all
;; but the left-most buffer.
(setq-default helm-reuse-last-window-split-state t
helm-split-window-in-side-p t))
(after! helm-ag (after! helm-swoop
;; Helm-ag needs a little coaxing for it to cooperate with shackle. Mostly to prevent (setq helm-swoop-split-window-function (lambda ($buf) (narf/popup-buffer $buf))))
;; it from switching between windows and buffers.
(defadvice helm-ag--edit-abort (around helm-ag-edit-abort-popup-compat activate)
(cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
(narf/popup-close nil t t))
(defadvice helm-ag--edit-commit (around helm-ag-edit-commit-popup-compat activate)
(cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
(narf/popup-close nil t t))
(defadvice helm-ag--edit (around helm-ag-edit-popup-compat activate)
(cl-letf (((symbol-function 'other-window) 'ignore)
((symbol-function 'switch-to-buffer) 'narf/popup-buffer))
ad-do-it)))
(after! quickrun (after! helm-ag
;; This allows us to run code several times in a row without having to close the popup ;; Helm-ag needs a little coaxing for it to cooperate with shackle. Mostly to prevent
;; window and move back to the code buffer. ;; it from switching between windows and buffers.
(defun narf*quickrun-close-popup (&optional _ _ _ _) (defadvice helm-ag--edit-abort (around helm-ag-edit-abort-popup-compat activate)
(let* ((buffer (get-buffer quickrun/buffer-name)) (cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
(window (and buffer (get-buffer-window buffer)))) (narf/popup-close nil t t))
(when buffer (defadvice helm-ag--edit-commit (around helm-ag-edit-commit-popup-compat activate)
(shut-up! (quickrun/kill-running-process)) (cl-letf (((symbol-function 'select-window) 'ignore)) ad-do-it)
(narf/popup-close window nil t)))) (narf/popup-close nil t t))
(advice-add 'quickrun :before 'narf*quickrun-close-popup) (defadvice helm-ag--edit (around helm-ag-edit-popup-compat activate)
(advice-add 'quickrun-region :before 'narf*quickrun-close-popup) (cl-letf (((symbol-function 'other-window) 'ignore)
((symbol-function 'switch-to-buffer) 'narf/popup-buffer))
ad-do-it)))
;; Turns on `nlinum-mode', and ensures window is scrolled to EOF (after! quickrun
(defun narf|quickrun-after-run () ;; This allows us to run code several times in a row without having to close the popup
(let ((window (get-buffer-window quickrun/buffer-name))) ;; window and move back to the code buffer.
(with-selected-window window (defun narf*quickrun-close-popup (&optional _ _ _ _)
(goto-char (point-min))))) (let* ((buffer (get-buffer quickrun/buffer-name))
(add-hook 'quickrun-after-run-hook 'narf|quickrun-after-run) (window (and buffer (get-buffer-window buffer))))
(add-hook 'quickrun/mode-hook 'narf|hide-mode-line)) (when buffer
(shut-up! (quickrun/kill-running-process))
(narf/popup-close window nil t))))
(advice-add 'quickrun :before 'narf*quickrun-close-popup)
(advice-add 'quickrun-region :before 'narf*quickrun-close-popup)
(add-hook! org-load ;; Turns on `nlinum-mode', and ensures window is scrolled to EOF
;; This ensures org-src-edit yields control of its buffer to shackle. (defun narf|quickrun-after-run ()
(defun org-src-switch-to-buffer (buffer context) (let ((window (get-buffer-window quickrun/buffer-name)))
(pop-to-buffer buffer)) (with-selected-window window
(goto-char (point-min)))))
(add-hook 'quickrun-after-run-hook 'narf|quickrun-after-run)
(add-hook 'quickrun/mode-hook 'narf|hide-mode-line))
;; And these for org-todo, org-link and agenda (add-hook! org-load
(defun org-pop-to-buffer-same-window (&optional buffer-or-name norecord label) ;; This ensures org-src-edit yields control of its buffer to shackle.
"Pop to buffer specified by BUFFER-OR-NAME in the selected window." (defun org-src-switch-to-buffer (buffer context)
(display-buffer buffer-or-name)) (pop-to-buffer buffer))
(defun org-switch-to-buffer-other-window (&rest args) ;; And these for org-todo, org-link and agenda
(mapc (lambda (b) (defun org-pop-to-buffer-same-window (&optional buffer-or-name norecord label)
(let ((buf (if (stringp b) (get-buffer-create b) b))) "Pop to buffer specified by BUFFER-OR-NAME in the selected window."
(pop-to-buffer buf t t))) (display-buffer buffer-or-name))
args))
;; Taming Org-agenda! (defun org-switch-to-buffer-other-window (&rest args)
(defun narf/org-agenda-quit () (mapc (lambda (b)
"Necessary to finagle org-agenda into shackle popups and behave properly on quit." (let ((buf (if (stringp b) (get-buffer-create b) b)))
(interactive) (pop-to-buffer buf t t)))
(if org-agenda-columns-active args))
(org-columns-quit)
(let ((buf (current-buffer)))
(and (not (eq org-agenda-window-setup 'current-window))
(not (one-window-p))
(delete-window))
(kill-buffer buf)
(setq org-agenda-archives-mode nil
org-agenda-buffer nil))))
(map! :map org-agenda-mode-map ;; Taming Org-agenda!
:e "<escape>" 'narf/org-agenda-quit (defun narf/org-agenda-quit ()
:e "ESC" 'narf/org-agenda-quit "Necessary to finagle org-agenda into shackle popups and behave properly on quit."
:e [escape] 'narf/org-agenda-quit (interactive)
"q" 'narf/org-agenda-quit (if org-agenda-columns-active
"Q" 'narf/org-agenda-quit)) (org-columns-quit)
(let ((buf (current-buffer)))
(and (not (eq org-agenda-window-setup 'current-window))
(not (one-window-p))
(delete-window))
(kill-buffer buf)
(setq org-agenda-archives-mode nil
org-agenda-buffer nil))))
(after! realgud (map! :map org-agenda-mode-map
;; This allows realgud debuggers to run in a popup. :e "<escape>" 'narf/org-agenda-quit
;; TODO Find a more elegant advice-based solution :e "ESC" 'narf/org-agenda-quit
;; FIXME Causes realgud:cmd-* to focus popup on every invocation :e [escape] 'narf/org-agenda-quit
(defun realgud:run-process(debugger-name script-filename cmd-args minibuffer-history &optional no-reset) "q" 'narf/org-agenda-quit
(let ((cmd-buf)) "Q" 'narf/org-agenda-quit))
(setq cmd-buf
(apply 'realgud-exec-shell debugger-name script-filename (after! realgud
(car cmd-args) no-reset (cdr cmd-args))) ;; This allows realgud debuggers to run in a popup.
(let ((process (get-buffer-process cmd-buf))) ;; TODO Find a more elegant advice-based solution
(if (and process (eq 'run (process-status process))) ;; FIXME Causes realgud:cmd-* to focus popup on every invocation
(progn (defun realgud:run-process(debugger-name script-filename cmd-args minibuffer-history &optional no-reset)
(pop-to-buffer cmd-buf) (let ((cmd-buf))
(define-key evil-emacs-state-local-map (kbd "ESC ESC") 'narf/debug-quit) (setq cmd-buf
(realgud:track-set-debugger debugger-name) (apply 'realgud-exec-shell debugger-name script-filename
(realgud-cmdbuf-info-in-debugger?= 't) (car cmd-args) no-reset (cdr cmd-args)))
(realgud-cmdbuf-info-cmd-args= cmd-args) (let ((process (get-buffer-process cmd-buf)))
(when cmd-buf (if (and process (eq 'run (process-status process)))
(switch-to-buffer cmd-buf)
(when realgud-cmdbuf-info
(let* ((info realgud-cmdbuf-info)
(cmd-args (realgud-cmdbuf-info-cmd-args info))
(cmd-str (mapconcat 'identity cmd-args " ")))
(set minibuffer-history
(list-utils-uniq (cons cmd-str (eval minibuffer-history))))))))
;; else
(progn (progn
(if cmd-buf (switch-to-buffer cmd-buf)) (pop-to-buffer cmd-buf)
(message "Error running command: %s" (mapconcat 'identity cmd-args " "))))) (define-key evil-emacs-state-local-map (kbd "ESC ESC") 'narf/debug-quit)
cmd-buf)))) (realgud:track-set-debugger debugger-name)
(realgud-cmdbuf-info-in-debugger?= 't)
(realgud-cmdbuf-info-cmd-args= cmd-args)
(when cmd-buf
(switch-to-buffer cmd-buf)
(when realgud-cmdbuf-info
(let* ((info realgud-cmdbuf-info)
(cmd-args (realgud-cmdbuf-info-cmd-args info))
(cmd-str (mapconcat 'identity cmd-args " ")))
(set minibuffer-history
(list-utils-uniq (cons cmd-str (eval minibuffer-history))))))))
;; else
(progn
(if cmd-buf (switch-to-buffer cmd-buf))
(message "Error running command: %s" (mapconcat 'identity cmd-args " ")))))
cmd-buf)))
(provide 'core-popup) (provide 'core-popup)
;;; core-popup.el ends here ;;; core-popup.el ends here

View file

@ -1,5 +1,10 @@
;;; core-ui.el --- interface & mode-line config ;;; core-ui.el --- interface & mode-line config
;; y/n instead of yes/no
(fset 'yes-or-no-p 'y-or-n-p)
(defvar narf-fringe-size 3 "Default fringe width")
(setq-default (setq-default
blink-matching-paren nil ; don't blink--too distracting blink-matching-paren nil ; don't blink--too distracting
show-paren-delay 0.075 show-paren-delay 0.075
@ -36,8 +41,6 @@
fringe-indicator-alist (delq (assoc 'continuation fringe-indicator-alist) fringe-indicator-alist (delq (assoc 'continuation fringe-indicator-alist)
fringe-indicator-alist)) fringe-indicator-alist))
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
;; Ask for confirmation on exit only if there are real buffers left ;; Ask for confirmation on exit only if there are real buffers left
(when window-system (when window-system
(setq confirm-kill-emacs (setq confirm-kill-emacs
@ -47,7 +50,7 @@
t)))) t))))
(load-theme narf-current-theme t) (load-theme narf-current-theme t)
(tooltip-mode -1) ; show tooltips in echo area (tooltip-mode -1) ; show tooltips in echo area
;; set up minibuffer and fringe ;; set up minibuffer and fringe
(if (not window-system) (if (not window-system)
(menu-bar-mode -1) (menu-bar-mode -1)
@ -160,8 +163,7 @@
:commands (rainbow-mode) :commands (rainbow-mode)
:init :init
;; hl-line-mode and rainbow-mode don't play well together ;; hl-line-mode and rainbow-mode don't play well together
(add-hook! (sass-mode scss-mode less-css-mode) (add-hook 'rainbow-mode-hook 'narf|hl-line-off))
'(rainbow-mode narf|hl-line-off)))
(use-package nlinum (use-package nlinum
:commands nlinum-mode :commands nlinum-mode

View file

@ -9,7 +9,7 @@
;; narf|… A hook ;; narf|… A hook
;; narf*… An advising function ;; narf*… An advising function
;; narf.… Custom prefix commands ;; narf.… Custom prefix commands
;; …! Macro ;; …! Macro or shortcut alias
;; ;;
;; Autoloaded functions are in {core,modules}/defuns/defuns-*.el ;; Autoloaded functions are in {core,modules}/defuns/defuns-*.el
;; ;;
@ -79,21 +79,14 @@
;; Variables ;; Variables
;; ;;
(defvar narf-leader-prefix "," "Prefix key for <leader> maps")
(defvar narf-localleader-prefix "\\" "Prefix key for <localleader> maps")
;; Buffers/Files
(defvar narf-unreal-buffers '("^ ?\\*.+\\*" (defvar narf-unreal-buffers '("^ ?\\*.+\\*"
image-mode image-mode
dired-mode dired-mode
reb-mode reb-mode
messages-buffer-mode) messages-buffer-mode)
"A list of regexps or modes whose buffers are considered unreal, and will be "A list of regexps or modes whose buffers are considered unreal, and will be
ignored when using `narf:next-real-buffer' and `narf:previous-real-buffer', and ignored when using `narf:next-real-buffer' and `narf:previous-real-buffer' (or
killed by `narf/kill-unreal-buffers'. killed by `narf/kill-unreal-buffers', or after `narf/kill-real-buffer').")
`narf/kill-real-buffer' will also gloss over these buffers when finding a new
buffer to display.")
(defvar narf-ignore-buffers '("*Completions*" "*Compile-Log*" "*inferior-lisp*" (defvar narf-ignore-buffers '("*Completions*" "*Compile-Log*" "*inferior-lisp*"
"*Fuzzy Completions*" "*Apropos*" "*Help*" "*cvs*" "*Fuzzy Completions*" "*Apropos*" "*Help*" "*cvs*"
@ -131,21 +124,19 @@ gets killed.")
"A list of files that count as 'project files', which determine whether a "A list of files that count as 'project files', which determine whether a
folder is the root of a project or not.") folder is the root of a project or not.")
;; Fringe/margins
(defvar narf-fringe-size 6 "Default width to use for the fringes.")
;; ;;
;; Bootstrap ;; Libraries
;; ;;
(require 'f) (require 'f)
(autoload 'use-package "use-package" "" nil 'macro)
(unless (require 'autoloads nil t) (unless (require 'autoloads nil t)
(load (concat narf-emacs-dir "/scripts/generate-autoloads.el")) (load (concat narf-emacs-dir "/scripts/generate-autoloads.el"))
(require 'autoloads)) (require 'autoloads))
(require 'core-defuns) (require 'core-defuns)
(autoload 'use-package "use-package" "" nil 'macro)
(use-package anaphora (use-package anaphora
:commands (awhen aif acond awhile)) :commands (awhen aif acond awhile))
@ -204,13 +195,14 @@ enable multiple minor modes for the same regexp.")
;; ;;
(add-hook! after-init (add-hook! after-init
;; We add this to `after-init-hook' to allow errors to stop this advice ;; We add this to `after-init-hook' to allow errors to stop it
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate) (defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
"Prevent annoying \"Active processes exist\" query when you quit Emacs." "Prevent annoying \"Active processes exist\" query when you quit Emacs."
(cl-flet ((process-list ())) ad-do-it)) (cl-flet ((process-list ())) ad-do-it))
;; Don't display anything ;; Prevent any auto-displayed text...
(advice-add 'display-startup-echo-area-message :override 'ignore) (advice-add 'display-startup-echo-area-message :override 'ignore)
;; ...so we can display our own
(message ":: Loaded in %.3fs" (message ":: Loaded in %.3fs"
(float-time (time-subtract (current-time) emacs-start-time)))) (float-time (time-subtract (current-time) emacs-start-time))))

View file

@ -47,6 +47,10 @@
(defconst narf-terminal-theme 'narf-dark) (defconst narf-terminal-theme 'narf-dark)
(defconst narf-default-font (font-spec :family "Fira Mono" :size 12)) (defconst narf-default-font (font-spec :family "Fira Mono" :size 12))
(defconst narf-leader-prefix "," "Prefix for <leader> bindings")
(defconst narf-localleader-prefix "\\" "Prefix for <localleader> bindings")
;; Load packages
(narf `(core ; core/core.el (narf `(core ; core/core.el
;; OS-specific config ;; OS-specific config
@ -74,6 +78,7 @@
module-cc ; C/C++/Obj-C madness module-cc ; C/C++/Obj-C madness
module-crystal ; ruby at the speed of c module-crystal ; ruby at the speed of c
module-csharp ; unity, .NET, and mono shenanigans module-csharp ; unity, .NET, and mono shenanigans
module-css ; #big-bang::before { content: ""; }
module-data ; config and data formats module-data ; config and data formats
module-go ; the hipster dialect module-go ; the hipster dialect
module-haskell ; a language that's lazier than I am module-haskell ; a language that's lazier than I am
@ -92,7 +97,7 @@
module-scala ; Java, but good module-scala ; Java, but good
module-sh ; she sells Z-shells by the C XOR module-sh ; she sells Z-shells by the C XOR
module-text ; writing docs for people to ignore module-text ; writing docs for people to ignore
module-web ; #big-bang::before { content: ""; } module-web ; The end is always near </html>
;; Experimental ;; Experimental
;;module-eshell ; for inferior OSes *cough*windows ;;module-eshell ; for inferior OSes *cough*windows