extracted non-essential modules to a separate project
This commit is contained in:
parent
66bc6f0809
commit
23f3853a95
35 changed files with 30 additions and 1586 deletions
388
prelude/prelude-core.el
Normal file
388
prelude/prelude-core.el
Normal file
|
@ -0,0 +1,388 @@
|
|||
;;; prelude-core.el --- Emacs Prelude: core Prelude defuns.
|
||||
;;
|
||||
;; Copyright (c) 2011-2012 Bozhidar Batsov
|
||||
;;
|
||||
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
|
||||
;; URL: http://batsov.com/emacs-prelude
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: convenience
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Here are the definitions of most of the functions added by Prelude.
|
||||
|
||||
;;; License:
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 3
|
||||
;; of the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'cl)
|
||||
(require 'thingatpt)
|
||||
|
||||
(defun prelude-add-subfolders-to-load-path (parent-dir)
|
||||
"Adds all first level `parent-dir' subdirs to the
|
||||
Emacs load path."
|
||||
(dolist (f (directory-files parent-dir))
|
||||
(let ((name (concat parent-dir f)))
|
||||
(when (and (file-directory-p name)
|
||||
(not (equal f ".."))
|
||||
(not (equal f ".")))
|
||||
(add-to-list 'load-path name)))))
|
||||
|
||||
;; add the first level subfolders of vendor automatically
|
||||
(prelude-add-subfolders-to-load-path prelude-vendor-dir)
|
||||
|
||||
(defun prelude-open-with ()
|
||||
"Simple function that allows us to open the underlying
|
||||
file of a buffer in an external program."
|
||||
(interactive)
|
||||
(when buffer-file-name
|
||||
(shell-command (concat
|
||||
(if (eq system-type 'darwin)
|
||||
"open"
|
||||
(read-shell-command "Open current file with: "))
|
||||
" "
|
||||
buffer-file-name))))
|
||||
|
||||
(defun prelude-buffer-mode (buffer-or-name)
|
||||
(with-current-buffer buffer-or-name major-mode))
|
||||
|
||||
(defun prelude-visit-term-buffer ()
|
||||
(interactive)
|
||||
(if (not (get-buffer "*ansi-term*"))
|
||||
(ansi-term "/bin/bash")
|
||||
(switch-to-buffer "*ansi-term*")))
|
||||
|
||||
(defun prelude-google ()
|
||||
"Googles a query or region if any."
|
||||
(interactive)
|
||||
(browse-url
|
||||
(concat
|
||||
"http://www.google.com/search?ie=utf-8&oe=utf-8&q="
|
||||
(url-hexify-string (if mark-active
|
||||
(buffer-substring (region-beginning) (region-end))
|
||||
(read-string "Google: "))))))
|
||||
|
||||
(defun prelude-indent-rigidly-and-copy-to-clipboard (begin end indent)
|
||||
"Copy the selected code region to the clipboard, indented according
|
||||
to Markdown blockquote rules."
|
||||
(let ((buffer (current-buffer)))
|
||||
(with-temp-buffer
|
||||
(insert-buffer-substring-no-properties buffer begin end)
|
||||
(indent-rigidly (point-min) (point-max) indent)
|
||||
(clipboard-kill-ring-save (point-min) (point-max)))))
|
||||
|
||||
(defun prelude-indent-blockquote-and-copy-to-clipboard (begin end)
|
||||
"Copy the selected code region to the clipboard, indented according
|
||||
to markdown blockquote rules (useful to copy snippets to StackOverflow, Assembla, Github."
|
||||
(interactive "r")
|
||||
(prelude-indent-rigidly-and-copy-to-clipboard begin end 4))
|
||||
|
||||
(defun prelude-indent-nested-blockquote-and-copy-to-clipboard (begin end)
|
||||
"Copy the selected code region to the clipboard, indented according
|
||||
to markdown blockquote rules. Useful to add snippets under bullet points."
|
||||
(interactive "r")
|
||||
(prelude-indent-rigidly-and-copy-to-clipboard begin end 6))
|
||||
|
||||
(defun prelude-insert-empty-line ()
|
||||
"Insert an empty line after the current line and positon
|
||||
the curson at its beginning, according to the current mode."
|
||||
(interactive)
|
||||
(move-end-of-line nil)
|
||||
(open-line 1)
|
||||
(next-line 1)
|
||||
(indent-according-to-mode))
|
||||
|
||||
(defun prelude-move-line-up ()
|
||||
"Move up the current line."
|
||||
(interactive)
|
||||
(transpose-lines 1)
|
||||
(previous-line 2))
|
||||
|
||||
(defun prelude-move-line-down ()
|
||||
"Move down the current line."
|
||||
(interactive)
|
||||
(next-line 1)
|
||||
(transpose-lines 1)
|
||||
(previous-line 1))
|
||||
|
||||
;; add the ability to copy and cut the current line, without marking it
|
||||
(defadvice kill-ring-save (before slick-copy activate compile)
|
||||
"When called interactively with no active region, copy a single line instead."
|
||||
(interactive
|
||||
(if mark-active (list (region-beginning) (region-end))
|
||||
(message "Copied line")
|
||||
(list (line-beginning-position)
|
||||
(line-beginning-position 2)))))
|
||||
|
||||
(defadvice kill-region (before slick-cut activate compile)
|
||||
"When called interactively with no active region, kill a single line instead."
|
||||
(interactive
|
||||
(if mark-active (list (region-beginning) (region-end))
|
||||
(list (line-beginning-position)
|
||||
(line-beginning-position 2)))))
|
||||
|
||||
(defun prelude-indent-buffer ()
|
||||
"Indents the entire buffer."
|
||||
(interactive)
|
||||
(indent-region (point-min) (point-max)))
|
||||
|
||||
(defun prelude-indent-region-or-buffer ()
|
||||
"Indents a region if selected, otherwise the whole buffer."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(if (region-active-p)
|
||||
(progn
|
||||
(indent-region (region-beginning) (region-end))
|
||||
(message "Indented selected region."))
|
||||
(progn
|
||||
(prelude-indent-buffer)
|
||||
(message "Indented buffer.")))))
|
||||
|
||||
(defun prelude-annotate-todo ()
|
||||
"Put fringe marker on TODO: lines in the curent buffer."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward "TODO:" nil t)
|
||||
(let ((overlay (make-overlay (- (point) 5) (point))))
|
||||
(overlay-put overlay
|
||||
'before-string
|
||||
(propertize (format "A")
|
||||
'display '(left-fringe right-triangle)))))))
|
||||
|
||||
(defun prelude-copy-file-name-to-clipboard ()
|
||||
"Copy the current buffer file name to the clipboard."
|
||||
(interactive)
|
||||
(let ((filename (if (equal major-mode 'dired-mode)
|
||||
default-directory
|
||||
(buffer-file-name))))
|
||||
(when filename
|
||||
(kill-new filename)
|
||||
(message "Copied buffer file name '%s' to the clipboard." filename))))
|
||||
|
||||
(defun prelude-duplicate-current-line-or-region (arg)
|
||||
"Duplicates the current line or region ARG times.
|
||||
If there's no region, the current line will be duplicated. However, if
|
||||
there's a region, all lines that region covers will be duplicated."
|
||||
(interactive "p")
|
||||
(let (beg end (origin (point)))
|
||||
(if (and mark-active (> (point) (mark)))
|
||||
(exchange-point-and-mark))
|
||||
(setq beg (line-beginning-position))
|
||||
(if mark-active
|
||||
(exchange-point-and-mark))
|
||||
(setq end (line-end-position))
|
||||
(let ((region (buffer-substring-no-properties beg end)))
|
||||
(dotimes (i arg)
|
||||
(goto-char end)
|
||||
(newline)
|
||||
(insert region)
|
||||
(setq end (point)))
|
||||
(goto-char (+ origin (* (length region) arg) arg)))))
|
||||
|
||||
;; TODO doesn't work with uniquify
|
||||
(defun prelude-rename-file-and-buffer ()
|
||||
"Renames current buffer and file it is visiting."
|
||||
(interactive)
|
||||
(let ((name (buffer-name))
|
||||
(filename (buffer-file-name)))
|
||||
(if (not (and filename (file-exists-p filename)))
|
||||
(message "Buffer '%s' is not visiting a file!" name)
|
||||
(let ((new-name (read-file-name "New name: " filename)))
|
||||
(cond ((get-buffer new-name)
|
||||
(message "A buffer named '%s' already exists!" new-name))
|
||||
(t
|
||||
(rename-file name new-name 1)
|
||||
(rename-buffer new-name)
|
||||
(set-visited-file-name new-name)
|
||||
(set-buffer-modified-p nil)))))))
|
||||
|
||||
(defun prelude-delete-file-and-buffer ()
|
||||
"Kills the current buffer and deletes the file it is visiting"
|
||||
(interactive)
|
||||
(let ((filename (buffer-file-name)))
|
||||
(when filename
|
||||
(delete-file filename)
|
||||
(message "Deleted file %s" filename)))
|
||||
(kill-buffer))
|
||||
|
||||
(defun prelude-view-url ()
|
||||
"Open a new buffer containing the contents of URL."
|
||||
(interactive)
|
||||
(let* ((default (thing-at-point-url-at-point))
|
||||
(url (read-from-minibuffer "URL: " default)))
|
||||
(switch-to-buffer (url-retrieve-synchronously url))
|
||||
(rename-buffer url t)
|
||||
;; TODO: switch to nxml/nxhtml mode
|
||||
(cond ((search-forward "<?xml" nil t) (xml-mode))
|
||||
((search-forward "<html" nil t) (html-mode)))))
|
||||
|
||||
;; We have a number of turn-on-* functions since it's advised that lambda
|
||||
;; functions not go in hooks. Repeatedly evaluating an add-to-list with a
|
||||
;; hook value will repeatedly add it since there's no way to ensure
|
||||
;; that a lambda doesn't already exist in the list.
|
||||
|
||||
(defun prelude-turn-on-whitespace ()
|
||||
(whitespace-mode +1))
|
||||
|
||||
(defun prelude-turn-off-whitespace ()
|
||||
(whitespace-mode -1))
|
||||
|
||||
(defun prelude-turn-on-abbrev ()
|
||||
(abbrev-mode +1))
|
||||
|
||||
(defun prelude-turn-off-abbrev ()
|
||||
(abbrev-mode -1))
|
||||
|
||||
(defun prelude-untabify-buffer ()
|
||||
(interactive)
|
||||
(untabify (point-min) (point-max)))
|
||||
|
||||
(defun prelude-cleanup-buffer ()
|
||||
"Perform a bunch of operations on the whitespace content of a buffer."
|
||||
(interactive)
|
||||
(prelude-indent-buffer)
|
||||
(prelude-untabify-buffer)
|
||||
(whitespace-cleanup))
|
||||
|
||||
(defun prelude-eval-and-replace ()
|
||||
"Replace the preceding sexp with its value."
|
||||
(interactive)
|
||||
(backward-kill-sexp)
|
||||
(condition-case nil
|
||||
(prin1 (eval (read (current-kill 0)))
|
||||
(current-buffer))
|
||||
(error (message "Invalid expression")
|
||||
(insert (current-kill 0)))))
|
||||
|
||||
(defun prelude-recompile-init ()
|
||||
"Byte-compile all your dotfiles again."
|
||||
(interactive)
|
||||
(byte-recompile-directory prelude-dir 0)
|
||||
(byte-recompile-directory prelude-vendor-dir 0))
|
||||
|
||||
(defun prelude-regen-autoloads (&optional force-regen)
|
||||
"Regenerate the autoload definitions file if necessary and load it."
|
||||
(interactive "P")
|
||||
(let ((autoload-dir prelude-vendor-dir)
|
||||
(generated-autoload-file autoload-file))
|
||||
(when (or force-regen
|
||||
(not (file-exists-p autoload-file))
|
||||
(some (lambda (f) (file-newer-than-file-p f autoload-file))
|
||||
(directory-files autoload-dir t "\\.el$")))
|
||||
(message "Updating autoloads...")
|
||||
(let (emacs-lisp-mode-hook)
|
||||
(update-directory-autoloads autoload-dir))))
|
||||
(load autoload-file))
|
||||
|
||||
(defun prelude-sudo-edit (&optional arg)
|
||||
(interactive "p")
|
||||
(if (or arg (not buffer-file-name))
|
||||
(find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
|
||||
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
|
||||
|
||||
(defun prelude-switch-or-start (function buffer)
|
||||
"If the buffer is current, bury it, otherwise invoke the function."
|
||||
(if (equal (buffer-name (current-buffer)) buffer)
|
||||
(bury-buffer)
|
||||
(if (get-buffer buffer)
|
||||
(switch-to-buffer buffer)
|
||||
(funcall function))))
|
||||
|
||||
(defun prelude-insert-date ()
|
||||
"Insert a time-stamp according to locale's date and time format."
|
||||
(interactive)
|
||||
(insert (format-time-string "%c" (current-time))))
|
||||
|
||||
(defun prelude-conditionally-enable-paredit-mode ()
|
||||
"Enable paredit-mode in the minibuffer, during eval-expression."
|
||||
(if (eq this-command 'eval-expression)
|
||||
(paredit-mode 1)))
|
||||
|
||||
(add-hook 'minibuffer-setup-hook 'prelude-conditionally-enable-paredit-mode)
|
||||
|
||||
(defun prelude-recentf-ido-find-file ()
|
||||
"Find a recent file using ido."
|
||||
(interactive)
|
||||
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
|
||||
(when file
|
||||
(find-file file))))
|
||||
|
||||
(defun prelude-swap-windows ()
|
||||
"If you have 2 windows, it swaps them."
|
||||
(interactive)
|
||||
(if (/= (count-windows) 2)
|
||||
(message "You need exactly 2 windows to do this.")
|
||||
(let* ((w1 (first (window-list)))
|
||||
(w2 (second (window-list)))
|
||||
(b1 (window-buffer w1))
|
||||
(b2 (window-buffer w2))
|
||||
(s1 (window-start w1))
|
||||
(s2 (window-start w2)))
|
||||
(set-window-buffer w1 b2)
|
||||
(set-window-buffer w2 b1)
|
||||
(set-window-start w1 s2)
|
||||
(set-window-start w2 s1)))
|
||||
(other-window 1))
|
||||
|
||||
(defun prelude-kill-other-buffers ()
|
||||
"Kill all buffers but the current one. Doesn't mess with special buffers."
|
||||
(interactive)
|
||||
(dolist (buffer (buffer-list))
|
||||
(unless (or (eql buffer (current-buffer)) (not (buffer-file-name buffer)))
|
||||
(kill-buffer buffer))))
|
||||
|
||||
(defun prelude-restore-arrow-keys ()
|
||||
"Restores arrow keys navigation in buffers."
|
||||
(interactive)
|
||||
(global-set-key [up] 'previous-line)
|
||||
(global-set-key [down] 'next-line)
|
||||
(global-set-key [left] 'backward-char)
|
||||
(global-set-key [right] 'forward-char)
|
||||
(global-set-key [M-right] 'right-word)
|
||||
(global-set-key [M-left] 'left-word)
|
||||
(message "Arrow keys navigation in buffers in now allowed."))
|
||||
|
||||
(require 'repeat)
|
||||
|
||||
(defun make-repeatable-command (cmd)
|
||||
"Returns a new command that is a repeatable version of CMD.
|
||||
The new command is named CMD-repeat. CMD should be a quoted
|
||||
command.
|
||||
|
||||
This allows you to bind the command to a compound keystroke and
|
||||
repeat it with just the final key. For example:
|
||||
|
||||
(global-set-key (kbd \"C-c a\") (make-repeatable-command 'foo))
|
||||
|
||||
will create a new command called foo-repeat. Typing C-c a will
|
||||
just invoke foo. Typing C-c a a a will invoke foo three times,
|
||||
and so on."
|
||||
(fset (intern (concat (symbol-name cmd) "-repeat"))
|
||||
`(lambda ,(help-function-arglist cmd) ;; arg list
|
||||
,(format "A repeatable version of `%s'." (symbol-name cmd)) ;; doc string
|
||||
,(interactive-form cmd) ;; interactive form
|
||||
;; see also repeat-message-function
|
||||
(setq last-repeatable-command ',cmd)
|
||||
(repeat nil)))
|
||||
(intern (concat (symbol-name cmd) "-repeat")))
|
||||
|
||||
(provide 'prelude-core)
|
||||
;;; prelude-core.el ends here
|
282
prelude/prelude-editor.el
Normal file
282
prelude/prelude-editor.el
Normal file
|
@ -0,0 +1,282 @@
|
|||
;;; prelude-editor.el --- Emacs Prelude: enhanced core editing experience.
|
||||
;;
|
||||
;; Copyright (c) 2011-2012 Bozhidar Batsov
|
||||
;;
|
||||
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
|
||||
;; URL: http://batsov.com/emacs-prelude
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: convenience
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Refinements of the core editing experience in Emacs.
|
||||
|
||||
;;; License:
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 3
|
||||
;; of the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Code:
|
||||
|
||||
;; customize
|
||||
(defgroup editor nil
|
||||
"Emacs Prelude Editor enhancements"
|
||||
:group 'prelude)
|
||||
|
||||
;; Death to the tabs! However, tabs historically indent to the next
|
||||
;; 8-character offset; specifying anything else will cause *mass*
|
||||
;; confusion, as it will change the appearance of every existing file.
|
||||
;; In some cases (python), even worse -- it will change the semantics
|
||||
;; (meaning) of the program.
|
||||
;;
|
||||
;; Emacs modes typically provide a standard means to change the
|
||||
;; indentation width -- eg. c-basic-offset: use that to adjust your
|
||||
;; personal indentation width, while maintaining the style (and
|
||||
;; meaning) of any files you load.
|
||||
(setq-default indent-tabs-mode nil) ;; don't use tabs to indent
|
||||
(setq-default tab-width 8) ;; but maintain correct appearance
|
||||
|
||||
;; delete the selection with a keypress
|
||||
(delete-selection-mode t)
|
||||
|
||||
;; store all backup and autosave files in the tmp dir
|
||||
(setq backup-directory-alist
|
||||
`((".*" . ,temporary-file-directory)))
|
||||
(setq auto-save-file-name-transforms
|
||||
`((".*" ,temporary-file-directory t)))
|
||||
|
||||
;; revert buffers automatically when underlying files are changed externally
|
||||
(global-auto-revert-mode t)
|
||||
|
||||
;; hippie expand is dabbrev expand on steroids
|
||||
(setq hippie-expand-try-functions-list '(try-expand-dabbrev
|
||||
try-expand-dabbrev-all-buffers
|
||||
try-expand-dabbrev-from-kill
|
||||
try-complete-file-name-partially
|
||||
try-complete-file-name
|
||||
try-expand-all-abbrevs
|
||||
try-expand-list
|
||||
try-expand-line
|
||||
try-complete-lisp-symbol-partially
|
||||
try-complete-lisp-symbol))
|
||||
|
||||
;; smart indenting and pairing for all
|
||||
(electric-pair-mode t)
|
||||
(electric-indent-mode t)
|
||||
(electric-layout-mode t)
|
||||
|
||||
;; meaningful names for buffers with the same name
|
||||
(require 'uniquify)
|
||||
(setq uniquify-buffer-name-style 'forward)
|
||||
(setq uniquify-separator "/")
|
||||
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
|
||||
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
|
||||
|
||||
;; saveplace remembers your location in a file when saving files
|
||||
(setq save-place-file (concat user-emacs-directory "saveplace"))
|
||||
;; activate it for all buffers
|
||||
(setq-default save-place t)
|
||||
(require 'saveplace)
|
||||
|
||||
;; savehist keeps track of some history
|
||||
(setq savehist-additional-variables
|
||||
;; search entries
|
||||
'(search ring regexp-search-ring)
|
||||
;; save every minute
|
||||
savehist-autosave-interval 60
|
||||
;; keep the home clean
|
||||
savehist-file (concat user-emacs-directory "savehist"))
|
||||
(savehist-mode t)
|
||||
|
||||
;; save recent files
|
||||
(setq recentf-save-file (concat user-emacs-directory "recentf")
|
||||
recentf-max-saved-items 200
|
||||
recentf-max-menu-items 15)
|
||||
(recentf-mode t)
|
||||
|
||||
;; time-stamps
|
||||
;; when there's "Time-stamp: <>" in the first 10 lines of the file
|
||||
(setq time-stamp-active t
|
||||
;; check first 10 buffer lines for Time-stamp: <>
|
||||
time-stamp-line-limit 10
|
||||
time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; date format
|
||||
(add-hook 'write-file-hooks 'time-stamp) ; update when saving
|
||||
|
||||
;; use shift + arrow keys to switch between visible buffers
|
||||
(require 'windmove)
|
||||
(windmove-default-keybindings 'super)
|
||||
|
||||
;; automatically save buffers associated with files on buffer switch
|
||||
;; and on windows switch
|
||||
(defadvice switch-to-buffer (before save-buffer-now activate)
|
||||
(when buffer-file-name (save-buffer)))
|
||||
(defadvice other-window (before other-window-now activate)
|
||||
(when buffer-file-name (save-buffer)))
|
||||
(defadvice windmove-up (before other-window-now activate)
|
||||
(when buffer-file-name (save-buffer)))
|
||||
(defadvice windmove-down (before other-window-now activate)
|
||||
(when buffer-file-name (save-buffer)))
|
||||
(defadvice windmove-left (before other-window-now activate)
|
||||
(when buffer-file-name (save-buffer)))
|
||||
(defadvice windmove-right (before other-window-now activate)
|
||||
(when buffer-file-name (save-buffer)))
|
||||
|
||||
;; show-paren-mode: subtle highlighting of matching parens
|
||||
(show-paren-mode t)
|
||||
(setq show-paren-style 'parenthesis)
|
||||
|
||||
;; highlight the current line
|
||||
(global-hl-line-mode +1)
|
||||
|
||||
(require 'volatile-highlights)
|
||||
(volatile-highlights-mode t)
|
||||
|
||||
;; tramp, for sudo access
|
||||
(require 'tramp)
|
||||
;; keep in mind known issues with zsh - see emacs wiki
|
||||
(setq tramp-default-method "ssh")
|
||||
|
||||
;; ido-mode
|
||||
(ido-mode t)
|
||||
(setq ido-enable-prefix nil
|
||||
ido-enable-flex-matching t
|
||||
ido-create-new-buffer 'always
|
||||
ido-use-filename-at-point 'guess
|
||||
ido-max-prospects 10
|
||||
ido-default-file-method 'selected-window)
|
||||
|
||||
;; auto-completion in minibuffer
|
||||
(icomplete-mode +1)
|
||||
|
||||
(set-default 'imenu-auto-rescan t)
|
||||
|
||||
;; flyspell-mode does spell-checking on the fly as you type
|
||||
(setq ispell-program-name "aspell" ; use aspell instead of ispell
|
||||
ispell-extra-args '("--sug-mode=ultra"))
|
||||
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
|
||||
|
||||
(defun prelude-turn-on-flyspell ()
|
||||
"Force flyspell-mode on using a positive argument. For use in hooks."
|
||||
(interactive)
|
||||
(flyspell-mode +1))
|
||||
|
||||
(add-hook 'message-mode-hook 'prelude-turn-on-flyspell)
|
||||
(add-hook 'text-mode-hook 'prelude-turn-on-flyspell)
|
||||
|
||||
;; enable narrowing commands
|
||||
(put 'narrow-to-region 'disabled nil)
|
||||
(put 'narrow-to-page 'disabled nil)
|
||||
(put 'narrow-to-defun 'disabled nil)
|
||||
|
||||
;; enabled change region case commands
|
||||
(put 'upcase-region 'disabled nil)
|
||||
(put 'downcase-region 'disabled nil)
|
||||
|
||||
(require 'expand-region)
|
||||
|
||||
;; bookmarks
|
||||
(setq bookmark-default-file (concat user-emacs-directory "bookmarks")
|
||||
bookmark-save-flag 1)
|
||||
|
||||
;; enabled auto-fill mode in text-mode and all related modes
|
||||
(add-hook 'text-mode-hook 'turn-on-auto-fill)
|
||||
|
||||
;; load yasnippet
|
||||
(require 'yasnippet)
|
||||
(add-to-list 'yas/snippet-dirs prelude-snippets-dir)
|
||||
(add-to-list 'yas/snippet-dirs prelude-personal-snippets-dir)
|
||||
(yas/global-mode 1)
|
||||
|
||||
;; projectile is a project management mode
|
||||
(require 'projectile)
|
||||
(projectile-global-mode t)
|
||||
|
||||
(require 'helm-misc)
|
||||
(require 'helm-projectile)
|
||||
|
||||
(defun helm-prelude ()
|
||||
"Preconfigured `helm'."
|
||||
(interactive)
|
||||
(if (projectile-get-project-root)
|
||||
;; add project files and buffers when in project
|
||||
(helm-other-buffer '(helm-c-source-projectile-files-list
|
||||
helm-c-source-projectile-buffers-list
|
||||
helm-c-source-buffers-list
|
||||
helm-c-source-recentf
|
||||
helm-c-source-buffer-not-found)
|
||||
"*helm prelude*")
|
||||
;; otherwise fallback to helm-mini
|
||||
(helm-mini)))
|
||||
|
||||
|
||||
;; dired - reuse current buffer by pressing 'a'
|
||||
(put 'dired-find-alternate-file 'disabled nil)
|
||||
|
||||
;; ediff - don't start another frame
|
||||
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
|
||||
|
||||
;; clean up obsolete buffers automatically
|
||||
(require 'midnight)
|
||||
|
||||
;; automatically indenting yanked text if in programming-modes
|
||||
(defvar yank-indent-modes '(python-mode LaTeX-mode TeX-mode)
|
||||
"Modes in which to indent regions that are yanked (or yank-popped). Only
|
||||
modes that don't derive from `prog-mode' should be listed here.")
|
||||
|
||||
(defvar yank-advised-indent-threshold 1000
|
||||
"Threshold (# chars) over which indentation does not automatically occur.")
|
||||
|
||||
(defun yank-advised-indent-function (beg end)
|
||||
"Do indentation, as long as the region isn't too large."
|
||||
(if (<= (- end beg) yank-advised-indent-threshold)
|
||||
(indent-region beg end nil)))
|
||||
|
||||
(defadvice yank (after yank-indent activate)
|
||||
"If current mode is one of 'yank-indent-modes,
|
||||
indent yanked text (with prefix arg don't indent)."
|
||||
(if (and (not (ad-get-arg 0))
|
||||
(or (derived-mode-p 'prog-mode)
|
||||
(member major-mode yank-indent-modes)))
|
||||
(let ((transient-mark-mode nil))
|
||||
(yank-advised-indent-function (region-beginning) (region-end)))))
|
||||
|
||||
(defadvice yank-pop (after yank-pop-indent activate)
|
||||
"If current mode is one of 'yank-indent-modes,
|
||||
indent yanked text (with prefix arg don't indent)."
|
||||
(if (and (not (ad-get-arg 0))
|
||||
(or (derived-mode-p 'prog-mode)
|
||||
(member major-mode yank-indent-modes)))
|
||||
(let ((transient-mark-mode nil))
|
||||
(yank-advised-indent-function (region-beginning) (region-end)))))
|
||||
|
||||
;; abbrev config
|
||||
(add-hook 'text-mode-hook 'prelude-turn-on-abbrev)
|
||||
|
||||
;; make a shell script executable automatically on save
|
||||
(add-hook 'after-save-hook
|
||||
'executable-make-buffer-file-executable-if-script-p)
|
||||
|
||||
;; saner regex syntax
|
||||
(require 're-builder)
|
||||
(setq reb-re-syntax 'string)
|
||||
|
||||
;; enable Prelude's keybindings
|
||||
(prelude-global-mode t)
|
||||
|
||||
(provide 'prelude-editor)
|
||||
|
||||
;;; prelude-editor.el ends here
|
116
prelude/prelude-mode.el
Normal file
116
prelude/prelude-mode.el
Normal file
|
@ -0,0 +1,116 @@
|
|||
;;; prelude-mode.el --- Emacs Prelude: minor mode
|
||||
;;
|
||||
;; Copyright (c) 2011-2012 Bozhidar Batsov
|
||||
;;
|
||||
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
|
||||
;; URL: http://batsov.com/emacs-prelude
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: convenience
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; A minor mode defining a local keymap, plus a menu.
|
||||
|
||||
;;; License:
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 3
|
||||
;; of the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defvar prelude-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map (kbd "C-c o") 'prelude-open-with)
|
||||
(define-key map (kbd "C-c g") 'prelude-google)
|
||||
;; mimic popular IDEs binding, note that it doesn't work in a terminal session
|
||||
(define-key map [(shift return)] 'prelude-insert-empty-line)
|
||||
(define-key map [(control shift up)] 'prelude-move-line-up)
|
||||
(define-key map [(control shift down)] 'prelude-move-line-down)
|
||||
(define-key map (kbd "C-c n") 'prelude-cleanup-buffer)
|
||||
(define-key map (kbd "C-c f") 'prelude-recentf-ido-find-file)
|
||||
(define-key map (kbd "C-c i") 'prelude-ido-goto-symbol)
|
||||
(define-key map (kbd "C-M-\\") 'prelude-indent-region-or-buffer)
|
||||
(define-key map (kbd "C-c u") 'prelude-view-url)
|
||||
(define-key map (kbd "C-c e") 'prelude-eval-and-replace)
|
||||
(define-key map (kbd "C-c s") 'prelude-swap-windows)
|
||||
(define-key map (kbd "C-c d") 'prelude-duplicate-current-line-or-region)
|
||||
(define-key map (kbd "C-c r") 'prelude-rename-file-and-buffer)
|
||||
(define-key map (kbd "C-c t") 'prelude-visit-term-buffer)
|
||||
(define-key map (kbd "C-c k") 'prelude-kill-other-buffers)
|
||||
(define-key map (kbd "C-c h") 'helm-prelude)
|
||||
map)
|
||||
"Keymap for Prelude mode.")
|
||||
|
||||
(easy-menu-define prelude-mode-menu prelude-mode-map
|
||||
"Menu for Prelude mode"
|
||||
'("Prelude"
|
||||
("Files"
|
||||
["Open with..." prelude-open-with]
|
||||
["Delete file and buffer" prelude-delete-file-and-buffer]
|
||||
["Rename file and buffer" prelude-rename-file-and-buffer]
|
||||
["Copy file name to clipboard" prelude-copy-file-name-to-clipboard])
|
||||
|
||||
("Buffers"
|
||||
["Clean up buffer" prelude-cleanup-buffer]
|
||||
["Kill other buffers" prelude-kill-other-buffers])
|
||||
|
||||
("Editing"
|
||||
["Insert empty line" prelude-insert-empty-line]
|
||||
["Move line up" prelude-move-line-up]
|
||||
["Move line down" prelude-move-line-down]
|
||||
["Indent buffer" prelude-indent-buffer]
|
||||
["Indent buffer or region" prelude-indent-buffer-or-region]
|
||||
["Duplicate line or region" prelude-duplicate-current-line-or-region]
|
||||
["Copy to clipboard as blockquote" prelude-indent-blockquote-and-copy-to-clipboard]
|
||||
["Copy to clipboard as nested blockqoute" prelude-indent-nested-blockquote-and-copy-to-clipboard]
|
||||
["Insert date" prelude-insert-date]
|
||||
["Eval and replace" prelude-eval-and-replace])
|
||||
|
||||
("Navigation"
|
||||
["Enable arrow keys" prelude-restore-arrow-keys]
|
||||
["Go to symbol" prelude-ido-goto-symbol]
|
||||
["Helm" helm-prelude])
|
||||
|
||||
("Windows"
|
||||
["Swap windows" prelude-swap-windows])
|
||||
|
||||
("General"
|
||||
["Visit term buffer" prelude-visit-term-buffer]
|
||||
["Search in Google" prelude-google]
|
||||
["View URL" prelude-view-url])))
|
||||
|
||||
;; define minor mode
|
||||
(define-globalized-minor-mode prelude-global-mode prelude-mode prelude-on)
|
||||
|
||||
(defun prelude-on ()
|
||||
(prelude-mode t))
|
||||
|
||||
(defun prelude-off ()
|
||||
(easy-menu-remove))
|
||||
|
||||
(define-minor-mode prelude-mode
|
||||
"Minor mode to consolidate Emacs Prelude extensions."
|
||||
:lighter "Prelude"
|
||||
:keymap prelude-mode-map
|
||||
(if prelude-mode
|
||||
;; on start
|
||||
(easy-menu-add prelude-mode-menu prelude-mode-map)
|
||||
;; on stop
|
||||
(prelude-off)))
|
||||
|
||||
(provide 'prelude-mode)
|
||||
;;; prelude-mode.el ends here
|
9
prelude/prelude-osx.el
Normal file
9
prelude/prelude-osx.el
Normal file
|
@ -0,0 +1,9 @@
|
|||
;; On OS X Emacs doesn't use the shell PATH if it's not started from
|
||||
;; the shell. If you're using homebrew modifying the PATH is essential.
|
||||
(push "/usr/local/bin" exec-path)
|
||||
|
||||
;; Emacs users obviously have little need for Command and Option keys,
|
||||
;; but they do need Meta and Super
|
||||
(setq mac-command-modifier 'super)
|
||||
(setq mac-option-modifier 'meta)
|
||||
(provide 'prelude-osx)
|
65
prelude/prelude-packages.el
Normal file
65
prelude/prelude-packages.el
Normal file
|
@ -0,0 +1,65 @@
|
|||
;;; prelude-packages.el --- Emacs Prelude: default package selection.
|
||||
;;
|
||||
;; Copyright (c) 2011-2012 Bozhidar Batsov
|
||||
;;
|
||||
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
|
||||
;; URL: http://batsov.com/emacs-prelude
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: convenience
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Takes care of the automatic installation of all the packages required by
|
||||
;; Emacs Prelude.
|
||||
|
||||
;;; License:
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 3
|
||||
;; of the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'package)
|
||||
(require 'melpa)
|
||||
(add-to-list 'package-archives
|
||||
'("melpa" . "http://melpa.milkbox.net/packages/") t)
|
||||
(package-initialize)
|
||||
|
||||
(setq url-http-attempt-keepalives nil)
|
||||
|
||||
(defvar prelude-packages
|
||||
'(expand-region gist helm helm-projectile magit magithub
|
||||
rainbow-mode volatile-highlights yasnippet zenburn-theme)
|
||||
"A list of packages to ensure are installed at launch.")
|
||||
|
||||
(defun prelude-packages-installed-p ()
|
||||
(loop for p in prelude-packages
|
||||
when (not (package-installed-p p)) do (return nil)
|
||||
finally (return t)))
|
||||
|
||||
(unless (prelude-packages-installed-p)
|
||||
;; check for new packages (package versions)
|
||||
(message "%s" "Emacs Prelude is now refreshing its package database...")
|
||||
(package-refresh-contents)
|
||||
(message "%s" " done.")
|
||||
;; install the missing packages
|
||||
(dolist (p prelude-packages)
|
||||
(when (not (package-installed-p p))
|
||||
(package-install p))))
|
||||
|
||||
(provide 'prelude-packages)
|
||||
;;; prelude-packages.el ends here
|
92
prelude/prelude-ui.el
Normal file
92
prelude/prelude-ui.el
Normal file
|
@ -0,0 +1,92 @@
|
|||
;;; prelude-ui.el --- Emacs Prelude: UI optimizations and tweaks.
|
||||
;;
|
||||
;; Copyright (c) 2011-2012 Bozhidar Batsov
|
||||
;;
|
||||
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
|
||||
;; URL: http://batsov.com/emacs-prelude
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: convenience
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; We dispense with most of the point and click UI, reduce the startup noise,
|
||||
;; configure smooth scolling and a nice theme that's easy on the eyes (zenburn).
|
||||
|
||||
;;; License:
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 3
|
||||
;; of the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Code:
|
||||
|
||||
;; the toolbar is just a waste of valuable screen estate
|
||||
;; in a tty tool-bar-mode does not properly auto-load, and is
|
||||
;; already disabled anyway
|
||||
(when (fboundp 'tool-bar-mode)
|
||||
(tool-bar-mode -1))
|
||||
;; the menu bar is mostly useless as well
|
||||
;; but removing it under OS X doesn't make much sense
|
||||
(defun prelude-frame-config (frame)
|
||||
"Custom behaviours for new frames."
|
||||
(if (eq system-type 'darwin)
|
||||
(with-selected-frame frame
|
||||
(if (display-graphic-p)
|
||||
(modify-frame-parameters frame '((menu-bar-lines . 1)))
|
||||
(modify-frame-parameters frame '((menu-bar-lines . 0)))))
|
||||
(menu-bar-mode -1)))
|
||||
|
||||
;; run now
|
||||
(prelude-frame-config (selected-frame))
|
||||
;; and later
|
||||
(add-hook 'after-make-frame-functions 'prelude-frame-config)
|
||||
|
||||
;; the blinking cursor is nothing, but an annoyance
|
||||
(blink-cursor-mode -1)
|
||||
|
||||
;; disable startup screen
|
||||
(setq inhibit-startup-screen t)
|
||||
|
||||
;; nice scrolling
|
||||
(setq scroll-margin 0
|
||||
scroll-conservatively 100000
|
||||
scroll-preserve-screen-position 1)
|
||||
|
||||
;; mode line settings
|
||||
(line-number-mode t)
|
||||
(column-number-mode t)
|
||||
(size-indication-mode t)
|
||||
|
||||
;; make the fringe (gutter) smaller
|
||||
;; the argument is a width in pixels (the default is 8)
|
||||
(if (fboundp 'fringe-mode)
|
||||
(fringe-mode 4))
|
||||
|
||||
;; enable y/n answers
|
||||
(fset 'yes-or-no-p 'y-or-n-p)
|
||||
|
||||
;; more useful frame title, that show either a file or a
|
||||
;; buffer name (if the buffer isn't visiting a file)
|
||||
(setq frame-title-format
|
||||
'("" invocation-name " Prelude - " (:eval (if (buffer-file-name)
|
||||
(abbreviate-file-name (buffer-file-name))
|
||||
"%b"))))
|
||||
|
||||
;; use zenburn as the default theme
|
||||
(load-theme 'zenburn t)
|
||||
|
||||
(provide 'prelude-ui)
|
||||
;;; prelude-ui.el ends here
|
Loading…
Add table
Add a link
Reference in a new issue