Created
October 12, 2011 08:27
emacs customisations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; http://www.emacswiki.org/emacs/BrowseAproposURL | |
(require 'browse-url) | |
(setq apropos-url-alist | |
'( | |
("^g:? +\\(.*\\)" . ;; Google Web | |
"http://www.google.com/search?q=\\1") | |
("^g?w:? +\\(.*\\)" . ;; Google Wikipedia | |
"http://www.google.com/search?q=site%3Aen.wikipedia.org+\\1") | |
("^ge:? +\\(.*\\)" . ;; Emacs Wiki | |
"http://www.google.com/search?q=site%3Awww.emacswiki.org+\\1") | |
("^g?p:? +\\(.*\\)" . ;; Google Python | |
"http://www.google.com/search?hl=en&q=site%3Adocs.python.org%2Ftutorial+\\1") | |
("^g?i:? +\\(.*\\)" . ;; Google Images | |
"http://images.google.com/images?sa=N&tab=wi&q=\\1") | |
("^gd:? +\\(\\w+\\)|? *\\(\\w+\\) +\\(.*\\)" . ;; Google Dict | |
"http://www.google.com/dictionary?aq=f&langpair=\\1|\\2&q=\\3&hl=\\1") | |
("^hs:? +\\(.*\\)" . ;; Haskell | |
"http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=\\1") | |
("^\\(.*\\)" . ;; Default | |
"http://www.google.com/search?q=\\1") | |
)) | |
;; Don't know if it's the best way , but it seemed to work. (Requires emacs >= 20) | |
(defun browse-apropos-url (text &optional new-window) | |
(interactive (browse-url-interactive-arg "Location: ")) | |
(let ((text (replace-regexp-in-string | |
"^ *\\| *$" "" | |
(replace-regexp-in-string "[ \t\n]+" " " text)))) | |
(let ((url (assoc-default | |
text apropos-url-alist | |
'(lambda (a b) (let () (setq __braplast a) (string-match a b))) | |
text))) | |
(browse-url (replace-regexp-in-string __braplast url text) new-window)))) | |
(defun browse-apropos-url-on-region (min max text &optional new-window) | |
(interactive "r \nsAppend region to location: \nP") | |
(browse-apropos-url (concat text " " (buffer-substring min max)) new-window)) | |
(provide 'browse-apropos-url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'package) | |
(add-to-list 'package-archives | |
'("marmalade" . "http://marmalade-repo.org/packages/") t) | |
(package-initialize) | |
(when (not package-archive-contents) | |
(package-refresh-contents)) | |
;; Add in your own as you wish: | |
(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-bindings starter-kit-eshell starter-kit-js) | |
"A list of packages to ensure are installed at launch.") | |
(dolist (p my-packages) | |
(when (not (package-installed-p p)) | |
(package-install p))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(dired "D:/My Dropbox/") | |
(dired "C:/Documents and Settings/james/My Documents/") | |
(find-file "D:/My Dropbox/PlainText/Todo.txt") | |
(turn-off-auto-fill) | |
(auto-fill-mode -1) | |
(add-hook 'text-mode-hook 'turn-off-auto-fill) | |
;;; --------------------------------------------------------------------------- | |
(require 'dired-x) | |
(setq dired-omit-files | |
(rx (or (seq bol (? ".") "#") ;; emacs autosave files | |
(seq "~" eol) ;; backup-files | |
(seq bol "svn" eol) ;; svn dirs | |
(seq ".pyc" eol) | |
))) | |
(setq dired-omit-extensions | |
(append dired-latex-unclean-extensions | |
dired-bibtex-unclean-extensions | |
dired-texinfo-unclean-extensions)) | |
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1))) | |
(put 'dired-find-alternate-file 'disabled nil) | |
;;; --------------------------------------------------------------------------- | |
(defun uniquify-region-lines (beg end) | |
"Remove duplicate adjacent lines in region." | |
(interactive "*r") | |
(save-excursion | |
(goto-char beg) | |
(while (re-search-forward "^\\(.*\n\\)\\1+" end t) | |
(replace-match "\\1")))) | |
(defun uniquify-buffer-lines () | |
"Remove duplicate adjacent lines in the current buffer." | |
(interactive) | |
(uniquify-region-lines (point-min) (point-max))) | |
;;; --------------------------------------------------------------------------- | |
;; http://stackoverflow.com/questions/92971/how-do-i-set-the-size-of-emacs-window | |
;; http://www.gnu.org/software/emacs/windows/old/faq4.html | |
;; (set-frame-width (selected-frame) 80) | |
;; (set-frame-height (selected-frame) 60)) | |
;; (set-frame-position (selected-frame) 10 30) | |
(defun set-frame-size-according-to-resolution () | |
;; use 170 char wide window for largeish displays | |
;; and smaller 85 column windows for smaller displays | |
;; pick whatever numbers make sense for you | |
;; for the height, subtract a bit | |
;; from the screen height (for panels, menubars and | |
;; whatnot), then divide by the height of a char to | |
;; get the height we want | |
(interactive) | |
(if window-system | |
(let ((vtop '(top . 1)) | |
(vleft '(left . 1)) | |
(vwidth (if (> (x-display-pixel-width) 1280) | |
(cons 'width 170) | |
(cons 'width 85))) | |
(vheight (cons | |
'height | |
(/ (- (x-display-pixel-height) 80) | |
(frame-char-height))))) | |
(setq default-frame-alist (list vtop vleft vwidth vheight))))) | |
(set-frame-size-according-to-resolution) | |
(defun size-80-full () | |
(interactive) | |
(progn | |
(set-frame-width (selected-frame) 85) | |
(set-frame-height (selected-frame) (/ (- (x-display-pixel-height) 80) | |
(frame-char-height))) | |
(set-frame-position (selected-frame) 0 0))) | |
(defun size-160-full () | |
(interactive) | |
(progn | |
(set-frame-width (selected-frame) 170) | |
(set-frame-height (selected-frame) (/ (- (x-display-pixel-height) 80) | |
(frame-char-height))) | |
(set-frame-position (selected-frame) 0 0))) | |
(defun fullscreen () | |
(interactive) | |
(set-frame-parameter nil 'fullscreen | |
(if (frame-parameter nil 'fullscreen) nil 'fullboth))) | |
;;; --------------------------------------------------------------------------- | |
;; Misc | |
(transient-mark-mode 1) ;; highlight region | |
(cua-mode t) ;; various awesomeness | |
(global-visual-line-mode 1) ;; decent line/word wrapping | |
(column-number-mode t) ;; I want to know what column I am on | |
(setq mouse-drag-copy-region nil) ;; I don't want Emacs to copy the region | |
(delete-selection-mode 1) ; turn on text selection highlighting and | |
; make typing override | |
; selected text (Note: | |
; when delete-selection-mode | |
; is on, then | |
; transient-mark-mode is | |
; automatically on | |
; too.) | |
;; all auto-save go in one place | |
(defvar autosave-dir (expand-file-name "~/.emacs.d/autosave/")) | |
(setq auto-save-file-name-transforms `((".*" ,autosave-dir t))) | |
;; Line numbering | |
(require 'linum) | |
(setq linum-format "%d ") | |
(global-linum-mode 1) | |
;; Quick browser searching | |
(require 'browse-apropos-url) | |
;; Movement | |
(defun move-line-toggle () | |
"toggle between start and end of line" | |
(interactive) | |
(if (= (line-beginning-position) (point)) | |
(end-of-line) | |
(beginning-of-line))) | |
(defun move-buffer-toggle () | |
"toggle between start and end of buffer" | |
(interactive) | |
(if (= 1 (point)) | |
(end-of-buffer) | |
(beginning-of-buffer))) | |
;;; --------------------------------------------------------------------------- | |
;; Snippets | |
;; (require 'yasnippet) | |
;; (yas/initialize) | |
;; (yas/load-directory "/usr/share/emacs/site-lisp/yasnippet/snippets") | |
;; Complete as you type | |
;; (require 'auto-complete) | |
;; (require 'auto-complete-config) | |
;; (global-auto-complete-mode t) | |
;; (ac-python-keywords-initialize) | |
;; (ac-c++-keywords-initialize) | |
;;; -------------------------------------------------------------------------- | |
(defun 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)))) | |
(global-set-key (kbd "C-x f") 'recentf-ido-find-file) | |
;;; -------------------------------------------------------------------------- | |
;; Single line/word cursor movement | |
(global-set-key (kbd "M-j") 'backward-word) | |
(global-set-key (kbd "M-l") 'forward-word) | |
(global-set-key (kbd "M-i") 'previous-line) | |
(global-set-key (kbd "M-k") 'next-line) | |
;; Move by char | |
(global-set-key (kbd "M-J") 'backward-char) ; para-edit join sexp | |
(global-set-key (kbd "M-L") 'forward-char) ; was (prefix) | |
;; Move by paragraph | |
(global-set-key (kbd "M-u") 'backward-paragraph) | |
(global-set-key (kbd "M-o") 'forward-paragraph) | |
;; Move to beginning/ending of line | |
(global-set-key (kbd "M-h") 'move-line-toggle) | |
(global-set-key (kbd "M-H") 'move-line-toggle) | |
;; Move by screen (page up/down) | |
(global-set-key (kbd "M-I") 'scroll-down) | |
(global-set-key (kbd "M-K") 'scroll-up) | |
;; Move to beginning/ending of file | |
(global-set-key (kbd "M-J") 'move-buffer-toggle) | |
(global-set-key (kbd "M-L") 'move-buffer-toggle) | |
;; isearch | |
(global-set-key (kbd "M-;") 'isearch-forward) | |
(global-set-key (kbd "M-:") 'isearch-backward) | |
(global-set-key (kbd "M-p") 'recenter) | |
(defun kill-arrows () | |
(progn | |
(global-set-key (kbd "<down>") nil) | |
(global-set-key (kbd "<left>") nil) | |
(global-set-key (kbd "<up>") nil) | |
(global-set-key (kbd "<right>") nil) | |
(global-set-key (kbd "<insert>") nil) | |
(global-set-key (kbd "<home>") nil) | |
(global-set-key (kbd "<next>") nil) | |
(global-set-key (kbd "<delete>") nil) | |
(global-set-key (kbd "<end>") nil) | |
(global-set-key (kbd "<prior>") nil))) | |
;;; -------------------------------------------------------------------------- | |
(global-set-key [f5] 'browse-apropos-url) | |
(global-set-key [f6] 'comment-or-uncomment-region) | |
(global-set-key [f7] 'quick-calc) | |
(global-set-key [f8] 'eshell) | |
(global-set-key [f11] 'fullscreen) | |
(global-set-key [C-tab] 'other-window) | |
;;; -------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment