From 4495692a7f55c85ff2b51b4acc6a60028aacded6 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 29 Jan 2015 23:47:14 -0500 Subject: Split init-buffile.el --- lisp/init-buffers.el | 25 +++++++ lisp/init-buffile.el | 186 --------------------------------------------------- lisp/init-files.el | 162 ++++++++++++++++++++++++++++++++++++++++++++ lisp/init-org.el | 2 +- 4 files changed, 188 insertions(+), 187 deletions(-) create mode 100644 lisp/init-buffers.el delete mode 100644 lisp/init-buffile.el create mode 100644 lisp/init-files.el (limited to 'lisp') diff --git a/lisp/init-buffers.el b/lisp/init-buffers.el new file mode 100644 index 0000000..afdfe71 --- /dev/null +++ b/lisp/init-buffers.el @@ -0,0 +1,25 @@ + +(require 'uniquify) + +(setq uniquify-buffer-name-style 'forward) + +(setq ibuffer-expert t + ibuffer-restore-window-config-on-quit t + ibuffer-show-empty-filter-groups nil) + +(defun km/save-and-kill-buffer () + "Save current buffer and then kill it." + (interactive) + (save-buffer) + (kill-this-buffer)) + +(global-set-key (kbd "C-x K") 'kill-buffer-and-window) + +(key-chord-define-global ",d" 'km/save-and-kill-buffer) +(key-chord-define-global ",s" 'save-buffer) +(key-chord-define-global ",q" 'kill-this-buffer) + +;; Replace `list-buffers' with ibuffer. +(global-set-key (kbd "C-x C-b") 'ibuffer) + +(provide 'init-buffers) diff --git a/lisp/init-buffile.el b/lisp/init-buffile.el deleted file mode 100644 index 5ec3054..0000000 --- a/lisp/init-buffile.el +++ /dev/null @@ -1,186 +0,0 @@ -;;; Files and buffers - -(require 'uniquify) - -(setq require-final-newline t) - -(setq uniquify-buffer-name-style 'forward) - -(defun km/rename-current-buffer-file () - "Rename current buffer and file it is visiting." - (interactive) - (let ((name (buffer-name)) - (filename (buffer-file-name))) - (if (not (and filename (file-exists-p filename))) - (user-error "Buffer '%s' is not visiting a file!" name) - (let ((new-name (read-file-name "New name: " filename))) - (if (get-buffer new-name) - (user-error "A buffer named '%s' already exists!" new-name) - (rename-file filename new-name 1) - (rename-buffer new-name) - (set-visited-file-name new-name) - (set-buffer-modified-p nil) - (message "File '%s' successfully renamed to '%s'" - name (file-name-nondirectory new-name))))))) - -;; https://github.com/purcell/emacs.d/blob/master/lisp/init-utils.el -(defun km/delete-this-file () - "Delete the current file, and kill the buffer." - (interactive) - (or (buffer-file-name) (user-error "No file is currently being edited")) - (when (yes-or-no-p (format "Really delete '%s'?" - (file-name-nondirectory buffer-file-name))) - (delete-file (buffer-file-name)) - (kill-this-buffer))) - -;; http://emacs-fu.blogspot.com/2013/03/editing-with-root-privileges-once-more.html -(defun km/find-file-as-root () - "Automatically edit file with root-privileges." - (interactive) - (let ((file (ido-read-file-name "Edit as root: "))) - (unless (file-writable-p file) - (setq file (concat "/sudo:root@localhost:" file))) - (find-file file))) - -(defun km/save-and-kill-buffer () - "Save current buffer and then kill it." - (interactive) - (save-buffer) - (kill-this-buffer)) - -(global-set-key (kbd "C-x C-r") 'km/rename-current-buffer-file) -(global-set-key (kbd "C-x F") 'km/find-file-as-root) -(global-set-key (kbd "C-x K") 'kill-buffer-and-window) - -(key-chord-define-global ",d" 'km/save-and-kill-buffer) -(key-chord-define-global ",f" 'find-file) -(key-chord-define-global ",s" 'save-buffer) -(key-chord-define-global ",q" 'kill-this-buffer) - -(define-key ctl-x-4-map "v" 'view-file-other-window) - -(define-prefix-command 'km/file-map) -(global-set-key (kbd "C-c f") 'km/file-map) -(define-key km/file-map "v" 'view-file) - - -;;; Search - -(autoload 'vc-git-grep "vc-git" - "Run git grep, searching for REGEXP in FILES in directory DIR. -The search is limited to file names matching shell pattern FILES. -FILES may use abbreviations defined in `grep-files-aliases', e.g. -entering `ch' is equivalent to `*.[ch]'.") - -(add-hook 'grep-setup-hook 'km/grep-hide-header) - -(defun km/grep-hide-header () - (save-excursion - (goto-char (point-min)) - (forward-line 4) - (narrow-to-region (point) (point-max)))) - -(key-chord-define-global ",z" 'rgrep) - -(define-prefix-command 'km/file-search-map) -(define-key km/file-map "s" 'km/file-search-map) - -(define-key km/file-search-map "d" 'find-grep-dired) -(define-key km/file-search-map "D" 'find-dired) -(define-key km/file-search-map "f" 'grep-find) -(define-key km/file-search-map "g" 'lgrep) -(define-key km/file-search-map "G" 'grep) -(define-key km/file-search-map "n" 'find-name-dired) -(define-key km/file-search-map "r" 'rgrep) -(define-key km/file-search-map "v" 'vc-git-grep) -(define-key km/file-search-map "z" 'zrgrep) - - -;;; Ibuffer - -(setq ibuffer-expert t - ibuffer-restore-window-config-on-quit t - ibuffer-show-empty-filter-groups nil) - -;; Replace `list-buffers' with ibuffer. -(global-set-key (kbd "C-x C-b") 'ibuffer) - - - -;;; Recent files - -(setq recentf-max-menu-items 15 - recentf-max-saved-items 200 - recentf-save-file "~/.emacs.d/cache/recentf") -(recentf-mode) - -;; Modified from prelude -(defun km/recentf-find-file () - "Find a file from `recentf-list'." - (interactive) - (find-file (km/read-recent-file))) - -(defun km/recentf-find-file-other-window () - "Find a file from `recentf-list' in other window." - (interactive) - (find-file-other-window (km/read-recent-file))) -;; This overrides `find-file-read-only-other-window', but -;; `view-file-other-window', which I map to 'v', has the same -;; functionality. -(defun km/read-recent-file () - (ido-completing-read "Choose recent file: " recentf-list nil t)) - -(key-chord-define-global ",r" 'km/recentf-find-file) -(define-key ctl-x-4-map "r" 'km/recentf-find-file-other-window) - - -;;; Scratch files - -(defvar km/find-scratch-buffers - '((?e ".el" "Elisp") - (?p ".py" "Python") - (?s ".sh" "Shell") - (?r ".r" "R") - (?h ".hs" "Haskell") - (?o ".org" "Org") - (?m ".md" "Markdown") - (?n "" "No mode")) - "List of scratch buffers. -Format of each element should be (CHARACTER EXTENSION DOC). DOC -is not required.") - -(defun km/scratch-find-file (erase) - "Find scratch buffer. - -Prompt with characters from `km/find-scratch-buffers' to -determine the extension of the scratch file. - -With prefix ERASE, delete contents of buffer." - (interactive "P") - (switch-to-buffer (km/scratch--find-file-no-select erase))) - -(defun km/scratch-find-file-other-window (erase) - "Like `km/find-scratch-file', but open buffer in another window." - (interactive "P") - (switch-to-buffer-other-window (km/scratch--find-file-no-select erase))) - -(defun km/scratch--find-file-no-select (erase) - (let ((scratch-buffer - (find-file-noselect (km/scratch--get-file-name)))) - (when erase - (with-current-buffer scratch-buffer - (erase-buffer))) - scratch-buffer)) - -;; This is based off of Projectile's commander. -(defun km/scratch--get-file-name () - (-let* ((choices (-map #'car km/find-scratch-buffers)) - (prompt (concat "Scratch buffer [" choices "]: ")) - (ch (read-char-choice prompt choices)) - ((_ ext _) (assq ch km/find-scratch-buffers))) - (concat "/tmp/scratch" ext))) - -(global-set-key (kbd "C-c s") 'km/scratch-find-file) -(define-key ctl-x-4-map "s" 'km/scratch-find-file-other-window) - -(provide 'init-buffile) diff --git a/lisp/init-files.el b/lisp/init-files.el new file mode 100644 index 0000000..ced1373 --- /dev/null +++ b/lisp/init-files.el @@ -0,0 +1,162 @@ + +(require 'uniquify) + +(setq require-final-newline t) + +(defun km/rename-current-buffer-file () + "Rename current buffer and file it is visiting." + (interactive) + (let ((name (buffer-name)) + (filename (buffer-file-name))) + (if (not (and filename (file-exists-p filename))) + (user-error "Buffer '%s' is not visiting a file!" name) + (let ((new-name (read-file-name "New name: " filename))) + (if (get-buffer new-name) + (user-error "A buffer named '%s' already exists!" new-name) + (rename-file filename new-name 1) + (rename-buffer new-name) + (set-visited-file-name new-name) + (set-buffer-modified-p nil) + (message "File '%s' successfully renamed to '%s'" + name (file-name-nondirectory new-name))))))) + +;; https://github.com/purcell/emacs.d/blob/master/lisp/init-utils.el +(defun km/delete-this-file () + "Delete the current file, and kill the buffer." + (interactive) + (or (buffer-file-name) (user-error "No file is currently being edited")) + (when (yes-or-no-p (format "Really delete '%s'?" + (file-name-nondirectory buffer-file-name))) + (delete-file (buffer-file-name)) + (kill-this-buffer))) + +;; http://emacs-fu.blogspot.com/2013/03/editing-with-root-privileges-once-more.html +(defun km/find-file-as-root () + "Automatically edit file with root-privileges." + (interactive) + (let ((file (ido-read-file-name "Edit as root: "))) + (unless (file-writable-p file) + (setq file (concat "/sudo:root@localhost:" file))) + (find-file file))) + +(global-set-key (kbd "C-x C-r") 'km/rename-current-buffer-file) +(global-set-key (kbd "C-x F") 'km/find-file-as-root) + +(key-chord-define-global ",f" 'find-file) + +(define-key ctl-x-4-map "v" 'view-file-other-window) + +(define-prefix-command 'km/file-map) +(global-set-key (kbd "C-c f") 'km/file-map) +(define-key km/file-map "v" 'view-file) + + +;;; Search + +(autoload 'vc-git-grep "vc-git" + "Run git grep, searching for REGEXP in FILES in directory DIR. +The search is limited to file names matching shell pattern FILES. +FILES may use abbreviations defined in `grep-files-aliases', e.g. +entering `ch' is equivalent to `*.[ch]'.") + +(add-hook 'grep-setup-hook 'km/grep-hide-header) + +(defun km/grep-hide-header () + (save-excursion + (goto-char (point-min)) + (forward-line 4) + (narrow-to-region (point) (point-max)))) + +(key-chord-define-global ",z" 'rgrep) + +(define-prefix-command 'km/file-search-map) +(define-key km/file-map "s" 'km/file-search-map) + +(define-key km/file-search-map "d" 'find-grep-dired) +(define-key km/file-search-map "D" 'find-dired) +(define-key km/file-search-map "f" 'grep-find) +(define-key km/file-search-map "g" 'lgrep) +(define-key km/file-search-map "G" 'grep) +(define-key km/file-search-map "n" 'find-name-dired) +(define-key km/file-search-map "r" 'rgrep) +(define-key km/file-search-map "v" 'vc-git-grep) +(define-key km/file-search-map "z" 'zrgrep) + + +;;; Recent files + +(setq recentf-max-menu-items 15 + recentf-max-saved-items 200 + recentf-save-file "~/.emacs.d/cache/recentf") +(recentf-mode) + +;; Modified from prelude +(defun km/recentf-find-file () + "Find a file from `recentf-list'." + (interactive) + (find-file (km/read-recent-file))) + +(defun km/recentf-find-file-other-window () + "Find a file from `recentf-list' in other window." + (interactive) + (find-file-other-window (km/read-recent-file))) +;; This overrides `find-file-read-only-other-window', but +;; `view-file-other-window', which I map to 'v', has the same +;; functionality. +(defun km/read-recent-file () + (ido-completing-read "Choose recent file: " recentf-list nil t)) + +(key-chord-define-global ",r" 'km/recentf-find-file) +(define-key ctl-x-4-map "r" 'km/recentf-find-file-other-window) + + +;;; Scratch files + +(defvar km/find-scratch-buffers + '((?e ".el" "Elisp") + (?p ".py" "Python") + (?s ".sh" "Shell") + (?r ".r" "R") + (?h ".hs" "Haskell") + (?o ".org" "Org") + (?m ".md" "Markdown") + (?n "" "No mode")) + "List of scratch buffers. +Format of each element should be (CHARACTER EXTENSION DOC). DOC +is not required.") + +(defun km/scratch-find-file (erase) + "Find scratch buffer. + +Prompt with characters from `km/find-scratch-buffers' to +determine the extension of the scratch file. + +With prefix ERASE, delete contents of buffer." + (interactive "P") + (switch-to-buffer (km/scratch--find-file-no-select erase))) + +(defun km/scratch-find-file-other-window (erase) + "Like `km/find-scratch-file', but open buffer in another window." + (interactive "P") + (switch-to-buffer-other-window (km/scratch--find-file-no-select erase))) + +(defun km/scratch--find-file-no-select (erase) + (let ((scratch-buffer + (find-file-noselect (km/scratch--get-file-name)))) + (when erase + (with-current-buffer scratch-buffer + (erase-buffer))) + scratch-buffer)) + +;; This is based off of Projectile's commander. +(defun km/scratch--get-file-name () + (-let* ((choices (-map #'car km/find-scratch-buffers)) + (prompt (concat "Scratch buffer [" choices "]: ")) + (ch (read-char-choice prompt choices)) + ((_ ext _) (assq ch km/find-scratch-buffers))) + (concat "/tmp/scratch" ext))) + +(global-set-key (kbd "C-c s") 'km/scratch-find-file) +(define-key ctl-x-4-map "s" 'km/scratch-find-file-other-window) + +(provide 'init-files) diff --git a/lisp/init-org.el b/lisp/init-org.el index 7a1b769..c033779 100644 --- a/lisp/init-org.el +++ b/lisp/init-org.el @@ -522,7 +522,7 @@ global value. A numeric prefix sets MAXLEVEL (defaults to 2)." (interactive) (org-open-file (km/read-recent-file))) -(after 'init-buffile +(after 'init-files (define-key km/file-map "a" 'km/org-open-annex-file) (define-key km/file-map "o" 'km/org-open-file) (define-key km/file-map "p" 'km/org-open-file-at-point) -- cgit v1.2.3