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
(defun isearch-yank-symbol ()
"*Put symbol at current point into search string."
(let ((sym (symbol-at-point)))
(if sym
(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))
(define-key isearch-mode-map "\C-w" 'isearch-yank-symbol)
(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.")))
(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"
(get major-mode 'find-tag-default-function)
(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"
(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."
(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."
(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."
(unless (bolp)
(forward-line -1)
(defun vi-open-line-below ()
"Insert a newline below the current line and put point at beginning."
(unless (eolp)
;; Kills live buffers, leaves some emacs work buffers
;; optained from
(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."
(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()
(move-beginning-of-line 1)
(open-line 1)
(next-line 1)
(defun rotate-windows ()
"Rotate your windows"
(cond ((not (> (count-windows)1))
(message "You can't rotate a single window!"))
(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")
(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)
(autoload 'zap-up-to-char "misc"
"Kill up to, but not including ARGth occurrence of CHAR.
\(fn arg char)"
;; Tags
(setq tags-case-fold-search nil)
(defun visit-project-tags ()
(let ((tags-file (concat (eproject-root) "TAGS")))
(visit-tags-table tags-file)
(message (concat "Loaded " tags-file))))
(defun build-ctags ()
(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/*"))
(message "tags built successfully")))
(defun my-find-tag ()
(if (file-exists-p (concat (eproject-root) "TAGS"))
;; 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."
(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-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 ()
(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 ()
(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 ()
(let ((process (get-text-property (point) 'tabulated-list-id)))
(cond ((and process
(processp process))
(delete-process process)
(error "no process at point!")))))