Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: a34db0caa5
Fetching contributors…

Cannot retrieve contributors at this time

178 lines (159 sloc) 5.924 kB
;;; rejeep-defuns.el --- Custom functions
(defun nuke-all-buffers ()
"Kill all buffers, leaving *scratch* only."
(lambda (x)
(kill-buffer x))
(defun open-line-below ()
"Open a line below the line the point is at.
Then move to that line and indent accordning to mode"
(move-end-of-line 1)
(defun open-line-above ()
"Open a line above the line the point is at.
Then move to that line and indent accordning to mode"
(move-beginning-of-line 1)
(forward-line -1)
;; NOTE: (region-beginning) and (region-end) are not saved in
;; variables since they can change after each clean step.
(defun clean-up-buffer-or-region ()
"Untabifies, indents and deletes trailing whitespace from buffer or region."
(unless (region-active-p)
(untabify (region-beginning) (region-end))
(indent-region (region-beginning) (region-end))
(narrow-to-region (region-beginning) (region-end))
(defun back-to-indentation-or-beginning-of-line ()
"Moves point back to indentation if there is any
non blank characters to the left of the cursor.
Otherwise point moves to beginning of line."
(if (= (point) (save-excursion (back-to-indentation) (point)))
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1))
((looking-back "\\s\)") (backward-list 1))
(t (self-insert-command arg))))
(defun duplicate-current-line-or-region (arg)
"Duplicates the current line or region ARG times.
If there's no region, the current line will be duplicated. However, if
there's a region, all lines that region covers will be duplicated."
(interactive "p")
(let (beg end (origin (point)))
(if (and (region-active-p) (> (point) (mark)))
(setq beg (line-beginning-position))
(if (region-active-p)
(setq end (line-end-position))
(let ((region (buffer-substring-no-properties beg end)))
(dotimes (i arg)
(goto-char end)
(insert region)
(setq end (point)))
(goto-char (+ origin (* (length region) arg) arg)))))
(defun swap-windows ()
"If you have 2 windows, it swaps them."
(cond ((/= (count-windows) 2)
(message "You need exactly 2 windows to do this."))
(let* ((w1 (first (window-list)))
(w2 (second (window-list)))
(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))))
(other-window 1))
(defun rename-this-buffer-and-file ()
"Renames current buffer and file it is visiting."
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))
(defun delete-this-buffer-and-file ()
"Removes file connected to current buffer and kills buffer."
(let ((filename (buffer-file-name))
(buffer (current-buffer))
(name (buffer-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(when (yes-or-no-p "Are you sure you want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
(defun google ()
"Googles a query or region if any."
(if (region-active-p)
(buffer-substring (region-beginning) (region-end))
(read-string "Query: ")))))
(defun comment-or-uncomment-current-line-or-region ()
"Comments or uncomments current current line or whole lines in region."
(let (min max)
(if (region-active-p)
(setq min (region-beginning) max (region-end))
(setq min (point) max (point)))
(progn (goto-char min) (line-beginning-position))
(progn (goto-char max) (line-end-position))))))
(defun join-line-or-lines-in-region ()
"Join this line or the lines in the selected region."
(cond ((region-active-p)
(let ((min (line-number-at-pos (region-beginning))))
(goto-char (region-end))
(while (> (line-number-at-pos) min)
(t (call-interactively 'join-line))))
(defun scroll-down-five ()
"Scrolls down five rows."
(scroll-down 5))
(defun scroll-up-five ()
"Scrolls up five rows."
(scroll-up 5))
(defun re-builder-large ()
"Just like `re-builder', only make the font and window larger."
(text-scale-increase 5)
(set-window-text-height (selected-window) 7))
(provide 'rejeep-defuns)
Jump to Line
Something went wrong with that request. Please try again.