Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
261 lines (229 sloc) 8.55 KB
(defun my-goto-match-beginning ()
(when (and isearch-forward isearch-other-end)
(goto-char isearch-other-end)))
(add-hook 'isearch-mode-end-hook 'my-goto-match-beginning)
(defadvice isearch-exit (after my-goto-match-beginning activate)
"Go to beginning of match."
(when (and isearch-forward isearch-other-end)
(goto-char isearch-other-end)))
;; Search back/forth for the symbol at point
;; See http://www.emacswiki.org/emacs/SearchAtPoint
(defun isearch-yank-symbol ()
"*Put symbol at current point into search string."
(interactive)
(let ((sym (symbol-at-point)))
(if sym
(progn
(setq isearch-regexp t
isearch-string (concat "\\_<" (regexp-quote (symbol-name sym)) "\\_>")
isearch-message (mapconcat 'isearch-text-char-description isearch-string "")
isearch-yank-flag t))
(ding)))
(isearch-search-and-update))
(define-key isearch-mode-map "\C-w" 'isearch-yank-symbol)
;; http://www.emacswiki.org/emacs/ZapToISearch
(defun zap-to-isearch (rbeg rend)
"Kill the region between the mark and the closest portion of
the isearch match string. The behaviour is meant to be analogous
to zap-to-char; let's call it zap-to-isearch. The deleted region
does not include the isearch word. This is meant to be bound only
in isearch mode. The point of this function is that oftentimes
you want to delete some portion of text, one end of which happens
to be an active isearch word. The observation to make is that if
you use isearch a lot to move the cursor around (as you should,
it is much more efficient than using the arrows), it happens a
lot that you could just delete the active region between the mark
and the point, not include the isearch word."
(interactive "r")
(when (not mark-active)
(error "Mark is not active"))
(let* ((isearch-bounds (list isearch-other-end (point)))
(ismin (apply 'min isearch-bounds))
(ismax (apply 'max isearch-bounds))
)
(if (< (mark) ismin)
(kill-region (mark) ismin)
(if (> (mark) ismax)
(kill-region ismax (mark))
(error "Internal error in isearch kill function.")))
(isearch-exit)
))
(define-key isearch-mode-map [(meta z)] 'zap-to-isearch)
(defun find-tag-at-point ()
"Runs find-tag with the word at point as the argument"
(interactive)
(find-tag
(funcall
(or
find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default))))
(defun push-mark-no-activate ()
"Pushes `point' to `mark-ring' and does not activate the region
Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
(interactive)
(push-mark (point) t nil)
(message "Pushed mark to ring"))
(global-set-key (kbd "C-`") 'push-mark-no-activate)
(defun jump-to-mark ()
"Jumps to the local mark, respecting the `mark-ring' order.
This is the same as using \\[set-mark-command] with the prefix argument."
(interactive)
(set-mark-command 1))
(global-set-key (kbd "M-`") 'jump-to-mark)
(defun exchange-point-and-mark-no-activate ()
"Identical to \\[exchange-point-and-mark] but will not activate the region."
(interactive)
(exchange-point-and-mark)
(deactivate-mark nil))
(define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
(defun vi-open-line-above ()
"Insert a newline above the current line and put point at beginning."
(interactive)
(unless (bolp)
(beginning-of-line))
(newline)
(forward-line -1)
(indent-according-to-mode))
(defun vi-open-line-below ()
"Insert a newline below the current line and put point at beginning."
(interactive)
(unless (eolp)
(end-of-line))
(newline-and-indent))
;; Kills live buffers, leaves some emacs work buffers
;; optained from http://www.chrislott.org/geek/emacs/dotemacs.html
(defun nuke-all-buffers (&optional list)
"For each buffer in LIST, kill it silently if unmodified. Otherwise ask.
LIST defaults to all existing live buffers."
(interactive)
(if (null list)
(setq list (buffer-list)))
(while list
(let* ((buffer (car list))
(name (buffer-name buffer)))
(and (not (string-equal name ""))
(not (string-equal name "*Messages*"))
(not (string-equal name "*scratch*"))
(/= (aref name 0) ? )
(kill-buffer buffer)))
(setq list (cdr list))))
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(open-line 1)
(next-line 1)
(yank))
(defun rotate-windows ()
"Rotate your windows"
(interactive)
(cond ((not (> (count-windows)1))
(message "You can't rotate a single window!"))
(t
(setq i 1)
(setq numWindows (count-windows))
(while (< i numWindows)
(let* (
(w1 (elt (window-list) i))
(w2 (elt (window-list) (+ (% i numWindows) 1)))
(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)
(setq i (1+ i)))))))
(defun unword (start end)
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(replace-string "" "\"")
(goto-char (point-min))
(replace-string "" "\"")
(goto-char (point-min))
(replace-string "" "'")
(goto-char (point-min))
(replace-string "" "-")
(goto-char (point-min))
(replace-string "" "")
(goto-char (point-min))
(replace-string "" "&#x2122;")
(goto-char (point-min))
(replace-string "²" "&#x00b2;")
)))
(defun add-to-loadpath (&rest dirs)
(dolist (dir dirs load-path)
(add-to-list 'load-path (expand-file-name dir) nil #'string=)))
(defun smart-kill-whole-line (&optional arg)
"A simple wrapper around `kill-whole-line' that respects indentation."
(interactive "P")
(kill-whole-line arg)
(back-to-indentation))
(autoload 'zap-up-to-char "misc"
"Kill up to, but not including ARGth occurrence of CHAR.
\(fn arg char)"
'interactive)
;; Tags
(setq tags-case-fold-search nil)
(defun visit-project-tags ()
(interactive)
(let ((tags-file (concat (eproject-root) "TAGS")))
(visit-tags-table tags-file)
(message (concat "Loaded " tags-file))))
(defun build-ctags ()
(interactive)
(message "building project tags")
(let ((default-directory (eproject-root)))
(shell-command (concat "exctags -e -R --extra=+fq --exclude=db --exclude=test --exclude=.git --exclude=public -f TAGS * " (s-trim (shell-command-to-string "rvm gemdir")) "/gems/*"))
(visit-project-tags)
(message "tags built successfully")))
(defun my-find-tag ()
(interactive)
(if (file-exists-p (concat (eproject-root) "TAGS"))
(visit-project-tags)
(build-ctags))
(etags-select-find-tag-at-point))
;; Load the tags file without asking
(setq tags-revert-without-query 1)
(defun toggle-frame-split ()
"If the frame is split vertically, split it horizontally or vice versa.
Assumes that the frame is only split into two."
(interactive)
(unless (= (length (window-list)) 2) (error "Can only toggle a frame split in two"))
(let ((split-vertically-p (window-combined-p)))
(delete-window) ; closes current window
(if split-vertically-p
(split-window-horizontally)
(split-window-vertically)) ; gives us a split with the other window twice
(switch-to-buffer nil))) ; restore the original window in this part of the frame
(defun git-extract-number-from-branch-name ()
(interactive)
(let ((current-branch-name (magit-get-current-branch)))
(progn (string-match "\\([0-9A-Za-z]+\\)" current-branch-name)
(insert (concat "[#" (match-string 1 current-branch-name) "] ")))))
(defun ignore-error-wrapper (fn)
"Funtion return new function that ignore errors.
The function wraps a function with `ignore-errors' macro."
(lexical-let ((fn fn))
(lambda ()
(interactive)
(ignore-errors
(funcall fn)))))
;; Use M-x list-processes to get the running processes list
;;(define-key process-menu-mode-map (kbd "C-k") 'joaot/delete-process-at-point)
(defun joaot/delete-process-at-point ()
(interactive)
(let ((process (get-text-property (point) 'tabulated-list-id)))
(cond ((and process
(processp process))
(delete-process process)
(revert-buffer))
(t
(error "no process at point!")))))