Skip to content

Instantly share code, notes, and snippets.

@ajvargo
Created April 14, 2011 13:54
Show Gist options
  • Save ajvargo/919524 to your computer and use it in GitHub Desktop.
Save ajvargo/919524 to your computer and use it in GitHub Desktop.
Little emacs setting to share with co-workers
;; keep a single instance of Emacs I can send crap to
;; allows me to do things like this in my bash profile
;; export GIT_EDITOR=/Applications/Emacs.app/Contents/MacOS/bin/emacsclient
;; send files to emacs from the command line as 'emacsclient <filename>'
(server-start)
;; 2 spaces instead of 4 for javascript
(setq js-indent-level 2)
;; turn on linum for mode xxx
;(add-hook 'xxx (lambda () (linum-mode 1)))
;; something I have seems to overwrite, so I need to do shift+RET, but
;; Indent newline automatically on hitting return
(defun set-reindent-then-newline-and-indent ()
(interactive)
(local-set-key (kbd "RET") 'reindent-then-newline-and-indent))
(add-hook 'ruby-mode-hook 'set-reindent-then-newline-and-indent)
;; pretty colors for shell
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(global-hl-line-mode t) ; Highlight the current line
(blink-cursor-mode t) ; I like the blinky
;; nuke trailing whitespaces when writing to a file
(add-hook 'write-file-hooks 'delete-trailing-whitespace)
;; Add stuff I need to my shell load path
;; I can't exactly what I have that not having this made angry. Magit maybe?
(when (equal system-type 'darwin)
(setenv "PATH" (concat "/opt/local/bin:/usr/local/bin:/usr/local/bin/git:/usr/local/git/bin/git:" (getenv "PATH")))
(push "/opt/local/bin" exec-path)
)
;;; Some custom functions I use
;; This could also be used for a file. Some people pre-load registers with bookmark
(defun ge ()
"Open the .emacs.d/ directory in dired."
(interactive)
(find-file "~/.emacs.d"))
(defun duplicate-line()
"Duplicates current line"
(interactive)
(kill-whole-line)
(yank)(yank))
;; For the line you are on, increment each number by 1, or the prefix
;; user_1 = stub_model(User, :org => org_1) =>
;; user_2 = stub_model(User, :org => org_2)
(defun increment-in-line (&optional n)
"Increment all numbers in a line by 1, or prefix argument"
(interactive "p")
(save-excursion
(beginning-of-line)
(while (re-search-forward "\\([0-9]+\\)" (line-end-position) t)
(replace-match (number-to-string (+ (string-to-number (match-string 1)) (if n n 1)))))))
;;; From some one else
;; if you are on a line, this copies it to the kill ring without selecting it.
;; So mid-line, with no selection, hit M-w, and it'll copy that line
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy a single line instead."
(interactive
(if (region-active-p) (list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))))
;; same as above, but kills
;; C-w
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if (region-active-p) (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment