Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
emacs customisations
(require 'browse-url)
(setq apropos-url-alist
("^g:? +\\(.*\\)" . ;; Google Web
("^g?w:? +\\(.*\\)" . ;; Google Wikipedia
("^ge:? +\\(.*\\)" . ;; Emacs Wiki
("^g?p:? +\\(.*\\)" . ;; Google Python
("^g?i:? +\\(.*\\)" . ;; Google Images
("^gd:? +\\(\\w+\\)|? *\\(\\w+\\) +\\(.*\\)" . ;; Google Dict
("^hs:? +\\(.*\\)" . ;; Haskell
("^\\(.*\\)" . ;; Default
;; 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)))
(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)
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "") t)
(when (not package-archive-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)))
(dired "D:/My Dropbox/")
(dired "C:/Documents and Settings/james/My Documents/")
(find-file "D:/My Dropbox/PlainText/Todo.txt")
(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
(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")
(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."
(uniquify-region-lines (point-min) (point-max)))
;;; ---------------------------------------------------------------------------
;; (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
(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
(/ (- (x-display-pixel-height) 80)
(setq default-frame-alist (list vtop vleft vwidth vheight)))))
(defun size-80-full ()
(set-frame-width (selected-frame) 85)
(set-frame-height (selected-frame) (/ (- (x-display-pixel-height) 80)
(set-frame-position (selected-frame) 0 0)))
(defun size-160-full ()
(set-frame-width (selected-frame) 170)
(set-frame-height (selected-frame) (/ (- (x-display-pixel-height) 80)
(set-frame-position (selected-frame) 0 0)))
(defun fullscreen ()
(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"
(if (= (line-beginning-position) (point))
(defun move-buffer-toggle ()
"toggle between start and end of buffer"
(if (= 1 (point))
;;; ---------------------------------------------------------------------------
;; 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."
(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 ()
(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
You can’t perform that action at this time.