Yet another big update
This commit is contained in:
parent
a8f32547a3
commit
c6862d1489
27 changed files with 474 additions and 355 deletions
|
@ -18,20 +18,21 @@
|
|||
evil-insert-state-cursor '("white" bar)
|
||||
evil-visual-state-cursor 'hollow)
|
||||
|
||||
(evil-mode)
|
||||
(evil-mode 1)
|
||||
|
||||
;; Always ensure evil-shift-width is consistent with tab-width
|
||||
(add-hook! 'find-file-hook (setq evil-shift-width tab-width))
|
||||
(add-hook! 'after-change-major-mode-hook (setq evil-shift-width tab-width))
|
||||
|
||||
;; highlight matching delimiters where it's important
|
||||
(defun show-paren-mode-off () (show-paren-mode -1))
|
||||
(add-hook 'evil-insert-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-insert-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-visual-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-visual-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-motion-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-motion-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-operator-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-operator-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-insert-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-insert-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-visual-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-visual-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-motion-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-motion-state-exit-hook 'show-paren-mode-off)
|
||||
(add-hook 'evil-operator-state-entry-hook 'show-paren-mode)
|
||||
(add-hook 'evil-operator-state-exit-hook 'show-paren-mode-off)
|
||||
|
||||
;; Disable highlights on insert-mode
|
||||
(add-hook 'evil-insert-state-entry-hook 'evil-ex-nohighlight)
|
||||
|
@ -45,26 +46,24 @@
|
|||
(evil-set-initial-state `,(car mode-map) `,(cdr mode-map)))
|
||||
|
||||
(progn ; evil plugins
|
||||
(use-package evil-exchange
|
||||
:config
|
||||
(defadvice evil-force-normal-state (before evil-esc-quit-exchange activate)
|
||||
(when evil-exchange--overlays
|
||||
(evil-exchange-cancel))))
|
||||
|
||||
(use-package evil-ex-registers)
|
||||
|
||||
(use-package evil-indent-textobject) ; vii/vai/vaI
|
||||
|
||||
(use-package evil-numbers)
|
||||
(use-package evil-matchit :config (global-evil-matchit-mode 1))
|
||||
(use-package evil-surround :config (global-evil-surround-mode 1))
|
||||
(use-package evil-visualstar :config (global-evil-visualstar-mode 1))
|
||||
|
||||
(use-package evil-matchit
|
||||
:config (global-evil-matchit-mode 1))
|
||||
(use-package evil-commentary
|
||||
:config (evil-commentary-mode 1))
|
||||
|
||||
(use-package evil-surround
|
||||
:config (global-evil-surround-mode 1))
|
||||
|
||||
(use-package evil-nerd-commenter
|
||||
:init (setq evilnc-hotkey-comment-operator "gc"))
|
||||
;; (use-package evil-nerd-commenter
|
||||
;; :commands (evilnc-comment-operator
|
||||
;; evilnc-comment-or-uncomment-lines
|
||||
;; evilnc-toggle-invert-comment-line-by-line
|
||||
;; evilnc-comment-or-uncomment-paragraphs
|
||||
;; evilnc-quick-comment-or-uncomment-to-the-line
|
||||
;; evilnc-copy-and-comment-lines)
|
||||
;; :init (setq evilnc-hotkey-comment-operator "gc"))
|
||||
|
||||
(use-package evil-jumper
|
||||
:init (setq evil-jumper-file (expand-file-name "jumplist" my-tmp-dir))
|
||||
|
@ -74,6 +73,18 @@
|
|||
evil-jumper-auto-save-interval 3600)
|
||||
(define-key evil-motion-state-map (kbd "H-i") 'evil-jumper/forward)))
|
||||
|
||||
(use-package evil-exchange
|
||||
:config
|
||||
(defadvice evil-force-normal-state (before evil-esc-quit-exchange activate)
|
||||
(when evil-exchange--overlays
|
||||
(evil-exchange-cancel))))
|
||||
|
||||
(use-package evil-search-highlight-persist
|
||||
:config
|
||||
(progn
|
||||
(global-evil-search-highlight-persist t)
|
||||
(set-face-attribute 'evil-search-highlight-persist-highlight-face nil :inherit 'evil-ex-lazy-highlight)))
|
||||
|
||||
(use-package evil-snipe
|
||||
:config
|
||||
(progn
|
||||
|
@ -81,7 +92,7 @@
|
|||
|
||||
(setq evil-snipe-smart-case t)
|
||||
(setq evil-snipe-override-evil t)
|
||||
(setq evil-snipe-scope 'visible)
|
||||
(setq evil-snipe-scope 'line)
|
||||
(setq evil-snipe-repeat-scope 'buffer)
|
||||
(setq evil-snipe-override-evil-repeat-keys nil)
|
||||
(setq-default evil-snipe-symbol-groups
|
||||
|
@ -94,10 +105,7 @@
|
|||
|
||||
'visual
|
||||
"z" 'evil-snipe-s
|
||||
"Z" 'evil-snipe-S)))
|
||||
|
||||
(use-package evil-visualstar
|
||||
:config (global-evil-visualstar-mode 1)))
|
||||
"Z" 'evil-snipe-S))))
|
||||
|
||||
(bind evil-ex-completion-map
|
||||
"C-r" #'evil-ex-paste-from-register ; registers in ex-mode
|
||||
|
@ -108,7 +116,7 @@
|
|||
|
||||
(progn ; evil hacks
|
||||
(defadvice evil-force-normal-state (before evil-esc-quit activate)
|
||||
(shut-up (evil-ex-nohighlight) ; turn off highlights
|
||||
(shut-up (evil-search-highlight-persist-remove-all) ; turn off highlights
|
||||
;; Exit minibuffer is alive
|
||||
(if (minibuffer-window-active-p (minibuffer-window))
|
||||
(my--minibuffer-quit))))
|
||||
|
@ -151,7 +159,7 @@
|
|||
(setq file-name
|
||||
;; %:p:h => the project root (or current directory otherwise)
|
||||
(replace-regexp-in-string "\\(^\\|[^\\\\]\\)\\(%:p\\)"
|
||||
(my--project-root) file-name t t 2))
|
||||
(project-root) file-name t t 2))
|
||||
(setq file-name
|
||||
;; %:p => the project root (or current directory otherwise)
|
||||
(replace-regexp-in-string "\\(^\\|[^\\\\]\\)\\(%:d\\)"
|
||||
|
@ -241,11 +249,11 @@ provided."
|
|||
(if bang (--save-exit)))
|
||||
(error "Directory doesn't exist: %s" dir))))
|
||||
|
||||
(evil-define-command my:rename-this-file (new-name &optional bang)
|
||||
(evil-define-command my:rename-this-file (new-name)
|
||||
"Renames current buffer and file it is visiting. Replaces %, # and other
|
||||
variables (see `evil-ex-replace-special-filenames')"
|
||||
:repeat nil
|
||||
(interactive "<f><!>")
|
||||
(interactive "<f>")
|
||||
(let ((name (buffer-name))
|
||||
(filename (buffer-file-name)))
|
||||
(if (not (and filename (file-exists-p filename)))
|
||||
|
@ -261,8 +269,6 @@ provided."
|
|||
(set-visited-file-name new-name)
|
||||
(set-buffer-modified-p nil)
|
||||
(save-place-forget-unreadable-files)
|
||||
(when bang
|
||||
(delete-file filename))
|
||||
(message "File '%s' successfully renamed to '%s'"
|
||||
name (file-name-nondirectory new-name)))))))
|
||||
|
||||
|
|
|
@ -25,32 +25,12 @@
|
|||
(unless (featurep 'ns) ad-do-it)))
|
||||
|
||||
;; Send current file to OSX apps
|
||||
(defun my--open-file-with (path &optional appName)
|
||||
(if (and appName
|
||||
(stringp appName)
|
||||
(not (string= "" appName)))
|
||||
(setq appName (concat "-a " appName ".app")))
|
||||
(shell-command (concat "open " appName " " (shell-quote-argument path))))
|
||||
|
||||
(defun my-open-with (appName file)
|
||||
(interactive "sApp name: ")
|
||||
(my--open-file-with file appName))
|
||||
|
||||
(defun my-send-to-transmit (file)
|
||||
(interactive "f")
|
||||
(my-open-with "Transmit" file))
|
||||
|
||||
(defun my-send-to-launchbar (file)
|
||||
(interactive "f")
|
||||
(my-open-with "LaunchBar" file))
|
||||
|
||||
(defun my-send-dir-to-launchbar (dir)
|
||||
(interactive "D")
|
||||
(my--open-file-with dir "LaunchBar"))
|
||||
|
||||
(defun my-send-dir-to-finder (dir)
|
||||
(interactive "D")
|
||||
(my--open-file-with dir "Finder"))
|
||||
(defun my-open-with (&optional app-name path)
|
||||
(interactive)
|
||||
(let ((app-name (if app-name (concat "-p " app-name)))
|
||||
(path (or path (if (eq major-mode 'dired-mode) (dired-get-file-for-visit) (buffer-file-name)))))
|
||||
(shell-command (concat "open " app-name " " (shell-quote-argument path)))))
|
||||
|
||||
|
||||
(provide 'core-osx)
|
||||
;;; core-osx.el ends here
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
;;;; Load Theme ;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(when window-system
|
||||
(set-frame-parameter nil 'alpha '(96 86))
|
||||
;; Load font
|
||||
(cycle-font 0))
|
||||
(cycle-font 0)) ; Load font
|
||||
|
||||
(add-to-list 'custom-theme-load-path my-themes-dir)
|
||||
(load-dark-theme)
|
||||
|
@ -12,7 +11,7 @@
|
|||
|
||||
;;;; GUI Settings ;;;;;;;;;;;;;;;;;;;;;;
|
||||
(tooltip-mode -1)
|
||||
(blink-cursor-mode 1) ; blink cursor
|
||||
(blink-cursor-mode -1) ; blink cursor
|
||||
(global-hl-line-mode 1) ; highlight line
|
||||
|
||||
(setq linum-format " %3d")
|
||||
|
@ -25,6 +24,7 @@
|
|||
(setq-default visible-bell nil) ; silence of the bells
|
||||
(setq-default use-dialog-box nil) ; avoid GUI
|
||||
(setq-default redisplay-dont-pause t)
|
||||
(setq window-combination-resize t)
|
||||
|
||||
;; do not soft-wrap lines
|
||||
(setq-default truncate-lines t)
|
||||
|
@ -44,10 +44,14 @@
|
|||
|
||||
|
||||
;;;; Modeline ;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(use-package vim-empty-lines-mode
|
||||
:config (global-vim-empty-lines-mode +1))
|
||||
|
||||
(use-package uniquify
|
||||
:config (setq uniquify-buffer-name-style 'post-forward
|
||||
uniquify-separator ":"
|
||||
uniquify-ignore-buffers-re "^\\*"))
|
||||
:config
|
||||
(setq uniquify-buffer-name-style 'post-forward-angle-brackets
|
||||
uniquify-separator ":"
|
||||
uniquify-ignore-buffers-re "^\\*"))
|
||||
|
||||
(use-package smart-mode-line
|
||||
:config
|
||||
|
@ -67,6 +71,9 @@
|
|||
" hs"
|
||||
" ElDoc"
|
||||
" wg"
|
||||
" ~"
|
||||
" s-/"
|
||||
" yas"
|
||||
) "\\|"))
|
||||
:init
|
||||
(progn
|
||||
|
|
181
core/core.el
181
core/core.el
|
@ -1,7 +1,6 @@
|
|||
(defconst is-mac (eq system-type 'darwin))
|
||||
(defconst is-linux (eq system-type 'gnu/linux))
|
||||
(defconst is-windows (or (eq system-type 'ms-dos)
|
||||
(eq system-type 'windows-nt)))
|
||||
(defconst is-windows (eq system-type 'windows-nt))
|
||||
|
||||
(when is-linux (add-to-list 'load-path "~/.cask"))
|
||||
(setq use-package-verbose DEBUG-MODE)
|
||||
|
@ -34,8 +33,10 @@
|
|||
(electric-indent-mode -1) ; In case of emacs >24.4
|
||||
|
||||
;;; window layout undo/redo
|
||||
(setq winner-boring-buffers '("*Completions*" "*Compile-Log*" "*inferior-lisp*"
|
||||
"*Fuzzy Completions*" "*Apropos*" "*Help*" "*cvs*"
|
||||
"*Buffer List*" "*Ibuffer*" "*esh command on file*"))
|
||||
(winner-mode 1)
|
||||
(setq winner-boring-buffers '("*Completions*" "*Help*"))
|
||||
|
||||
;;; UTF-8 please
|
||||
(setq locale-coding-system 'utf-8) ; pretty
|
||||
|
@ -59,8 +60,8 @@
|
|||
|
||||
(setq-default fill-column 80)
|
||||
|
||||
;; minibufferception? Nay!
|
||||
(setq-default enable-recursive-minibuffers nil)
|
||||
;; minibufferception? Yay!
|
||||
(setq-default enable-recursive-minibuffers t)
|
||||
|
||||
;; Sane scroll settings
|
||||
(setq scroll-margin 5)
|
||||
|
@ -100,6 +101,19 @@
|
|||
;; Fixes C-i's synonymity with TAB
|
||||
(keyboard-translate ?\C-i ?\H-i)
|
||||
|
||||
;; Save clipboard contents into kill-ring before replace them
|
||||
(setq save-interprogram-paste-before-kill t)
|
||||
|
||||
;; don't let the cursor go into minibuffer prompt
|
||||
;; Tip taken from Xah Lee: http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
|
||||
(setq minibuffer-prompt-properties
|
||||
'(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt))
|
||||
|
||||
;; remove annoying ellipsis when printing sexp in message buffer
|
||||
(setq eval-expression-print-length nil
|
||||
eval-expression-print-level nil)
|
||||
|
||||
|
||||
;;;; Backup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Disable all backups (that's what git/dropbox are for)
|
||||
(setq bookmark-save-flag t)
|
||||
|
@ -114,30 +128,27 @@
|
|||
;; Remember undo history
|
||||
(setq-default undo-tree-auto-save-history t)
|
||||
(setq-default undo-tree-history-directory-alist `(("." . ,my-tmp-dir-undo)))
|
||||
;;;; Save history across sessions
|
||||
(setq savehist-additional-variables '(search ring regexp-search-ring))
|
||||
(setq savehist-file (concat my-tmp-dir "savehist")) ; keep the home clean
|
||||
|
||||
;; Save history across sessions
|
||||
(require 'savehist)
|
||||
(setq savehist-file (concat my-tmp-dir "savehist") ; keep the home clean
|
||||
savehist-additional-variables '(kill-ring mark-ring global-mark-ring search-ring regexp-search-ring extended-command-history)
|
||||
history-length 1000)
|
||||
(savehist-mode 1)
|
||||
|
||||
;; Save cursor location across sessions
|
||||
(use-package saveplace
|
||||
:init
|
||||
(add-hook 'find-file-hook ; activate save-place for files that exist
|
||||
(lambda()
|
||||
(if (file-exists-p buffer-file-name)
|
||||
(setq save-place t))))
|
||||
:config
|
||||
(setq save-place-file (concat my-tmp-dir "saveplace")))
|
||||
(require 'saveplace)
|
||||
(setq-default save-place-file (concat my-tmp-dir "saveplace"))
|
||||
;; activate save-place only for files that exist
|
||||
(add-hook 'find-file-hook (lambda() (if (file-exists-p buffer-file-name) (setq save-place t))))
|
||||
|
||||
(use-package recentf
|
||||
:config
|
||||
(progn
|
||||
(setq recentf-max-menu-items 0)
|
||||
(setq recentf-max-saved-items 1000)
|
||||
(setq recentf-auto-cleanup 'never)
|
||||
(setq recentf-save-file (concat my-tmp-dir "recentf"))
|
||||
(setq recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last\\'" "\\.revive\\'", "/TAGS\\'"))
|
||||
(recentf-mode 1)))
|
||||
(require 'recentf)
|
||||
(setq recentf-save-file (concat my-tmp-dir "recentf"))
|
||||
(setq recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last\\'" "\\.revive\\'", "/TAGS\\'"))
|
||||
(setq recentf-max-menu-items 0)
|
||||
(setq recentf-max-saved-items 1000)
|
||||
(setq recentf-auto-cleanup 'never)
|
||||
(recentf-mode 1)
|
||||
|
||||
;; What we do every night, Pinkie...
|
||||
(defun display-startup-echo-area-message ()
|
||||
|
@ -154,41 +165,75 @@
|
|||
|
||||
(setq delete-trailing-lines nil)
|
||||
(add-hook 'makefile-mode-hook 'indent-tabs-mode) ; Use normal tabs in makefiles
|
||||
|
||||
;; Automatic minor modes ;;;;;;;;;;;
|
||||
(require 'f)
|
||||
(defvar project-root-files '(".git" ".hg" ".svn" "README" "README.md"))
|
||||
(defun project-root (&optional strict-p)
|
||||
"Get the path to the root of your project. Uses `project-root-files' to
|
||||
determine if a directory is a project."
|
||||
(catch 'found
|
||||
(f-traverse-upwards
|
||||
(lambda (path)
|
||||
(let ((path (file-truename path))
|
||||
(home (file-truename "~")))
|
||||
(if (f-equal? home path)
|
||||
(throw 'found (if strict-p nil default-directory))
|
||||
(dolist (file project-root-files)
|
||||
(when (f-exists? (expand-file-name file path))
|
||||
(throw 'found path)))))) default-directory)
|
||||
default-directory))
|
||||
|
||||
(defun project-has-files (&rest files)
|
||||
"Return non-nil if `file' exists in the project root."
|
||||
(let ((root (project-root))
|
||||
found-p file)
|
||||
(while (and files (not found-p))
|
||||
(setq file (pop files))
|
||||
(setq found-p (f-exists? (project-path-to file root))))
|
||||
found-p))
|
||||
|
||||
(defun project-path-to (file &optional root)
|
||||
(let ((root (or root (project-root))))
|
||||
(expand-file-name file root)))
|
||||
|
||||
(defun project-name ()
|
||||
(file-name-nondirectory (directory-file-name (project-root))))
|
||||
|
||||
(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-path ()
|
||||
"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-path)
|
||||
|
||||
;; Make sure scratch buffer is always "in a project"
|
||||
(defun set-project-scratch-buffer ()
|
||||
(let ((buffer (get-buffer "*scratch*"))
|
||||
(pwd (my--project-root)))
|
||||
(when (buffer-live-p buffer)
|
||||
(save-window-excursion
|
||||
(switch-to-buffer buffer)
|
||||
(unless (eq (my--project-root) pwd)
|
||||
(cd pwd)
|
||||
(rename-buffer (format "*scratch* (%s)" (file-name-nondirectory (directory-file-name pwd)))))))))
|
||||
(add-hook 'find-file-hook 'set-project-scratch-buffer)
|
||||
|
||||
|
||||
;;;; Behavior adjustments ;;;;;;;;;;;;;;;;
|
||||
;; Skip special buffers on next/previous-buffer or kill-this-buffer
|
||||
(defadvice next-buffer (after void-messages-buffer-in-next-buffer activate)
|
||||
(let ((buffer-name (buffer-name)))
|
||||
(when (and (string-match-p "\\`\\(\\*.+\\*\\|TAGS\\)$" buffer-name)
|
||||
(not (string-match-p "\\`\\*scratch*" buffer-name)))
|
||||
(next-buffer))))
|
||||
(defadvice previous-buffer (after avoid-messages-buffer-in-previous-buffer activate)
|
||||
(let ((buffer-name (buffer-name)))
|
||||
(when (and (string-match-p "\\`\\(\\*.+\\*\\|TAGS\\)$" buffer-name)
|
||||
(not (string-match-p "\\`\\*scratch*" buffer-name)))
|
||||
(previous-buffer))))
|
||||
(defadvice kill-this-buffer (after kill-this-buffer-no-switch-to-special-buffers activate)
|
||||
(let ((buffer-name (buffer-name)))
|
||||
(if (and (string-match-p "^\\*.+\\*" buffer-name)
|
||||
(not (string-match-p "^\\*scratch\\*" buffer-name)))
|
||||
(previous-buffer))))
|
||||
;; Don't kill the scratch buffer, just empty and bury it
|
||||
(defadvice kill-this-buffer (around kill-this-buffer-or-empty-scratch activate)
|
||||
(if (string-match-p "^\\*scratch\\*" (buffer-name))
|
||||
(bury-buffer)
|
||||
ad-do-it))
|
||||
(defun project-create-scratch-buffer ()
|
||||
(let* ((scratch-buffer (get-buffer-create "*scratch*"))
|
||||
(project-name (project-name))
|
||||
(root (project-root)))
|
||||
(save-window-excursion
|
||||
(switch-to-buffer scratch-buffer)
|
||||
(erase-buffer)
|
||||
(cd root)
|
||||
(insert ";; Project: " project-name "\n\n"))))
|
||||
(add-hook 'find-file-hook 'project-create-scratch-buffer)
|
||||
|
||||
|
||||
;;;; Utility plugins ;;;;;;;;;;;;;;;;;;
|
||||
|
@ -220,26 +265,20 @@
|
|||
(push '("^\\*scratch\\*.*" :regexp t :stick t) popwin:special-display-config)
|
||||
(push '(image-mode) popwin:special-display-config)
|
||||
|
||||
(after "evil"
|
||||
(evil-ex-define-cmd "l[ast]" 'popwin:popup-last-buffer)
|
||||
(evil-ex-define-cmd "m[sg]" 'popwin:messages))
|
||||
|
||||
(defun popwin:toggle-popup-window ()
|
||||
(interactive)
|
||||
(if (popwin:popup-window-live-p)
|
||||
(popwin:close-popup-window)
|
||||
(popwin:popup-last-buffer)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;;; Start the party ;;;;;;;;;;;;;;;;;;;
|
||||
(if is-mac (require 'core-osx))
|
||||
;; (if is-linux (require 'core-linux))
|
||||
;; (if is-windows (require 'core-windows))
|
||||
(cond (is-mac (require 'core-osx))
|
||||
(is-linux (require 'core-linux))
|
||||
(is-windows (require 'core-windows)))
|
||||
|
||||
(use-package server
|
||||
:config
|
||||
(unless (server-running-p)
|
||||
(server-start))))
|
||||
(require 'server)
|
||||
(unless (server-running-p) (server-start)))
|
||||
|
||||
|
||||
(provide 'core)
|
||||
|
|
|
@ -100,3 +100,36 @@ gets killed.")
|
|||
(if (s-matches? regexp (buffer-name b))
|
||||
(kill-buffer b)))
|
||||
(if buffer-list buffer-list (buffer-list))))
|
||||
|
||||
;; From spacemacs <https://github.com/syl20bnr/spacemacs/blob/master/spacemacs/funcs.el>
|
||||
;;;###autoload
|
||||
(defun my-next-real-buffer ()
|
||||
"Switch to the next buffer and avoid special buffers."
|
||||
(interactive)
|
||||
(switch-to-next-buffer)
|
||||
(let ((i 0))
|
||||
(while (and (< i 100) (string-equal "*" (substring (buffer-name) 0 1)))
|
||||
(1+ i)
|
||||
(switch-to-next-buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(defun my-previous-real-buffer ()
|
||||
"Switch to the previous buffer and avoid special buffers."
|
||||
(interactive)
|
||||
(switch-to-prev-buffer)
|
||||
(let ((i 0))
|
||||
(while (and (< i 100) (string-equal "*" (substring (buffer-name) 0 1)))
|
||||
(1+ i)
|
||||
(switch-to-prev-buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(defun my-kill-real-buffer ()
|
||||
"Kill buffer (but only bury scratch buffer)"
|
||||
(interactive)
|
||||
(let ((bname (buffer-name)))
|
||||
(cond ((string-match-p "^\\*scratch\\*" bname)
|
||||
(erase-buffer)
|
||||
(bury-buffer))
|
||||
((string-equal "*" (substring bname 0 1))
|
||||
(previous-buffer))
|
||||
(t (kill-this-buffer)))))
|
||||
|
|
|
@ -57,16 +57,21 @@ whitespace as possible, or just one char if that's not possible."
|
|||
((or indent-tabs-mode
|
||||
(= (point-at-bol) (point)))
|
||||
(call-interactively 'backward-delete-char))
|
||||
;; Otherwise, delete up to the nearest tab column
|
||||
(t (let ((movement (% (current-column) tab-width))
|
||||
(p (point)))
|
||||
(when (= movement 0)
|
||||
(setq movement tab-width))
|
||||
(save-match-data
|
||||
(if (string-match "\\w*\\(\\s-+\\)$"
|
||||
(buffer-substring-no-properties (- p movement) p))
|
||||
(backward-delete-char (- (match-end 1) (match-beginning 1)))
|
||||
(backward-delete-char-untabify 1)))))))
|
||||
;; Delete up to the nearest tab column IF only whitespace between point
|
||||
;; and bol.
|
||||
((looking-back "^[\\t ]*" (point-at-bol))
|
||||
(let ((movement (% (current-column) tab-width))
|
||||
(p (point)))
|
||||
(when (= movement 0)
|
||||
(setq movement tab-width))
|
||||
(save-match-data
|
||||
(if (string-match "\\w*\\(\\s-+\\)$"
|
||||
(buffer-substring-no-properties (- p movement) p))
|
||||
(backward-delete-char (- (match-end 1) (match-beginning 1)))
|
||||
(backward-delete-char-untabify 1)))))
|
||||
;; Otherwise do a regular delete
|
||||
(t
|
||||
(backward-delete-char-untabify 1))))
|
||||
|
||||
;;;###autoload
|
||||
(defun my.dumb-indent ()
|
||||
|
|
|
@ -30,12 +30,8 @@
|
|||
(load-dark-theme)))
|
||||
|
||||
;;;###autoload
|
||||
(defun cycle-font (&optional i)
|
||||
"Cycle between fonts specified in *fonts in init.el"
|
||||
(defun toggle-fullscreen ()
|
||||
(interactive)
|
||||
(if (numberp i)
|
||||
(setq my/cycle-font-i i)
|
||||
(if (>= my/cycle-font-i (1- (length *fonts)))
|
||||
(setq my/cycle-font-i 0)
|
||||
(cl-incf my/cycle-font-i)))
|
||||
(set-frame-font (nth my/cycle-font-i *fonts)))
|
||||
(set-frame-parameter nil 'fullscreen
|
||||
(when (not (frame-parameter nil 'fullscreen)) 'fullboth)))
|
||||
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
|
||||
;; String Defuns ;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;###autoload
|
||||
(after "s"
|
||||
(defun s-count-lines (s)
|
||||
"Get number of lines in a string"
|
||||
(length (s-lines s))))
|
||||
|
||||
;; File Defuns ;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;###autoload
|
||||
(after "f"
|
||||
(defmacro f--exists? (file dir)
|
||||
`(f-exists? (expand-file-name ,file ,dir))))
|
||||
(defun s-count-lines (s)
|
||||
"Get number of lines in a string"
|
||||
(length (s-lines s)))
|
||||
|
||||
;; Misc Defuns ;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;###autoload
|
||||
|
@ -32,3 +25,10 @@
|
|||
(minor-mode-key-binding key)
|
||||
(local-key-binding key)
|
||||
(global-key-binding key)))
|
||||
|
||||
;;;###autoload
|
||||
(defun echo (msg &rest args)
|
||||
"Display MSG in echo-area without logging it in *Messages* buffer."
|
||||
(interactive)
|
||||
(let ((message-log-max nil))
|
||||
(apply 'message msg args)))
|
||||
|
|
100
core/defuns.el
100
core/defuns.el
|
@ -1,41 +1,29 @@
|
|||
;; Convenience ;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun associate-mode (match mode)
|
||||
"Associate a major mode with a filepath through `auto-mode-alist'"
|
||||
(add-to-list 'auto-mode-alist (cons match mode)))
|
||||
|
||||
(defun associate-minor-mode (match mode)
|
||||
"Associate a minor mode with a filepath through `auto-minor-mode-alist'"
|
||||
(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)
|
||||
"A shortcut for: `(lambda () (interactive) ,@body)"
|
||||
`(lambda () (interactive) ,@body))
|
||||
|
||||
(defun add-hooks (hooks funs)
|
||||
"Add multiple hooks to multiple funs."
|
||||
(let ((funs (if (listp funs) funs (list funs)))
|
||||
(hooks (if (listp hooks) hooks (list hooks))))
|
||||
(dolist (hook hooks)
|
||||
(dolist (fun funs)
|
||||
(add-hook hook fun)))))
|
||||
|
||||
(defmacro add-hook! (hook &rest body)
|
||||
"A shortcut macro for `add-hook' that auto-wraps `body' in a lambda"
|
||||
`(add-hook ,hook (lambda() ,@body)))
|
||||
|
||||
;; Backwards compatibility
|
||||
;; Backwards compatible `with-eval-after-load'
|
||||
(unless (fboundp 'with-eval-after-load)
|
||||
(defmacro with-eval-after-load (file &rest body)
|
||||
`(eval-after-load ,file
|
||||
|
@ -52,13 +40,6 @@ the checking happens for all pairs in auto-minor-mode-alist"
|
|||
'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 (&rest keys)
|
||||
|
@ -73,9 +54,9 @@ the checking happens for all pairs in auto-minor-mode-alist"
|
|||
(t
|
||||
(if (stringp key)
|
||||
(setq key (kbd key)))
|
||||
(setq def (pop keys))
|
||||
(when (null def)
|
||||
(when (eq (length keys) 0)
|
||||
(user-error "No definition for '%s' keybinding" key))
|
||||
(setq def (pop keys))
|
||||
(if (null state-list)
|
||||
(if (null keymap)
|
||||
(global-set-key key def)
|
||||
|
@ -118,12 +99,17 @@ key-chord-define."
|
|||
(defun disable-final-newline ()
|
||||
(set (make-local-variable 'require-final-newline) nil))
|
||||
|
||||
(defun load-init-files ()
|
||||
;; (mapc 'require io-modules)
|
||||
(dolist (module my-modules)
|
||||
(message "%s" (symbol-name module))
|
||||
(with-demoted-errors "#### ERROR: %s"
|
||||
(require module))))
|
||||
|
||||
;; Font Defuns ;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun cycle-font (&optional i)
|
||||
"Cycle between fonts specified in *fonts in init.el"
|
||||
(interactive)
|
||||
(if (numberp i)
|
||||
(setq my/cycle-font-i i)
|
||||
(if (>= my/cycle-font-i (1- (length *fonts)))
|
||||
(setq my/cycle-font-i 0)
|
||||
(cl-incf my/cycle-font-i)))
|
||||
(set-frame-font (nth my/cycle-font-i *fonts)))
|
||||
|
||||
|
||||
;;;; Global Defuns ;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -138,5 +124,39 @@ to abort the minibuffer."
|
|||
(delete-windows-on "*Completions*"))
|
||||
(abort-recursive-edit)))
|
||||
|
||||
(defun my--line-at-click ()
|
||||
"Determine the line number at click"
|
||||
(save-excursion
|
||||
(let ((click-y (cddr (mouse-position)))
|
||||
(debug-on-error t)
|
||||
(line-move-visual t))
|
||||
(goto-char (window-start))
|
||||
(next-line (1- click-y))
|
||||
(1+ (line-number-at-pos)))))
|
||||
|
||||
(defun my-select-linum (event)
|
||||
"Set point as *linum-mdown-line*"
|
||||
(interactive "e")
|
||||
(mouse-select-window event)
|
||||
(goto-line (my--line-at-click))
|
||||
(evil-visual-line)
|
||||
(setq *linum-mdown-line*
|
||||
(line-number-at-pos)))
|
||||
|
||||
(defun my-select-block ()
|
||||
"Select the current block of text between blank lines."
|
||||
(interactive)
|
||||
(let (p1 p2)
|
||||
(progn
|
||||
(if (re-search-backward "\n[ \t]*\n" nil "move")
|
||||
(progn (re-search-forward "\n[ \t]*\n")
|
||||
(setq p1 (point)))
|
||||
(setq p1 (point)))
|
||||
(if (re-search-forward "\n[ \t]*\n" nil "move")
|
||||
(progn (re-search-backward "\n[ \t]*\n")
|
||||
(setq p2 (point)))
|
||||
(setq p2 (point))))
|
||||
(set-mark p1)))
|
||||
|
||||
|
||||
(provide 'defuns)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue