Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
243 lines (211 sloc) 7.78 KB
;; I-search with initial contents
(global-set-key '[(control *)] 'isearch-forward-at-point)
(defvar isearch-initial-string nil)
(defun isearch-set-initial-string ()
(remove-hook 'isearch-mode-hook 'isearch-set-initial-string)
(setq isearch-string isearch-initial-string)
(defun isearch-forward-at-point (&optional regexp-p no-recursive-edit)
"Interactive search forward for the symbol at point."
(interactive "P\np")
(if regexp-p (isearch-forward regexp-p no-recursive-edit)
(let* ((end (progn (skip-syntax-forward "w_") (point)))
(begin (progn (skip-syntax-backward "w_") (point))))
(if (eq begin end)
(isearch-forward regexp-p no-recursive-edit)
(setq isearch-initial-string (buffer-substring begin end))
(add-hook 'isearch-mode-hook 'isearch-set-initial-string)
(isearch-forward regexp-p no-recursive-edit)))))
;Duplicate current line down
(global-set-key '[(control meta d)] 'my-duplicate-line-or-region)
(defun my-duplicate-region (beg end &optional sep)
"Duplicate the region"
(interactive "*r")
(let ((p (point)))
(copy-region-as-kill beg end)
(message "%d" (point))
(goto-char end)
(if (stringp sep) (insert sep))
(goto-char p)))
(defun my-duplicate-line-or-region ()
"duplicate the region if active otherwise the current line"
(if mark-active
(my-duplicate-region (point) (mark))
(progn (my-duplicate-region (point-at-bol) (point-at-eol) "\n")(next-line))))
;Down/UP the current line
(global-set-key '[(control x) (up)] 'my-up-line)
(global-set-key '[(control x) (down)] 'my-down-line)
(defun my-down-line()
(let ((col (current-column)))
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(forward-char col)
(defun my-up-line()
(let ((col (current-column)))
(transpose-lines 1)
(forward-line -2)
(forward-char col)
;; behave like vi's O command
(defun open-previous-line (arg)
"Open a new line before the current one.
See also `newline-and-indent'."
(interactive "p")
(open-line arg)
(when newline-and-indent
(global-set-key (kbd "C-o") 'open-previous-line)
;; autoindent open-*-lines
(defvar newline-and-indent t
"Modify the behavior of the open-*-line functions to cause them to autoindent.")
; if no selection just comment line or comment selection
(defun my-comment-line-or-region ()
(interactive "*")
(if (and mark-active transient-mark-mode)
(comment-or-uncomment-region (region-beginning) (region-end) nil)
(move-beginning-of-line nil)
(set-mark-command nil)
(move-end-of-line nil)
(comment-dwim nil)
(global-set-key (read-kbd-macro "C-;") 'my-comment-line-or-region)
(global-set-key (read-kbd-macro "M-;") 'comment-dwim)
;Hack dired to launch files with 'l' key.
(defun my-dired-launch-command ()
(case system-type
(gnu/linux "gnome-open") ;right for gnome (ubuntu), not for other systems
(darwin "open"))
(dired-get-marked-files t current-prefix-arg)))
;; Remap goto-line to show temporary the line number.
(global-set-key [remap goto-line] 'goto-line-with-feedback)
(defun goto-line-with-feedback ()
"Show line numbers temporarily, while prompting for the line number input"
(linum-mode 1)
(goto-line (read-number "Goto line: ")))
(linum-mode -1)))
; Insert an empty line after the current line.
; Position the cursor at its beginning, according to the current mode.
(defun smart-open-line ()
(move-end-of-line nil)
(global-set-key [(shift return)] 'smart-open-line)
; Kill to the beginning of line (i.e: reverse c-k)
(global-set-key (kbd "C-<backspace>") (lambda ()
(kill-line 0)
;Kill whole line but stay at the same place.
(global-set-key (kbd "C-S-k") (lambda ()
(let ((p (point)))
(goto-char p))))
(defun my-hippie-expand-lines ()
"Try to expand entire line."
(let ((hippie-expand-try-functions-list '(try-expand-line
(hippie-expand nil)))
(global-set-key (kbd "C-?") 'my-hippie-expand-lines)
(defun my-top-join-line ()
"Join the current line with the line beneath it."
(delete-indentation 1))
(global-set-key (kbd "C-S-j") 'my-top-join-line)
(defun smarter-move-beginning-of-line (arg)
(interactive "^p")
(setq arg (or arg 1))
;; Move lines first
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(when (= orig-point (point))
(move-beginning-of-line 1))))
;; remap C-a to `smarter-move-beginning-of-line'
(global-set-key [remap move-beginning-of-line] 'smarter-move-beginning-of-line)
;; From
(defun my-toggle-fullscreen ()
"Toggle full screen"
nil 'fullscreen
(when (not (frame-parameter nil 'fullscreen)) 'fullboth)))
; Quickly try a lisp on the web downloading and evaluating it.
; From me.
(defun my-try-el(url)
"Quickly try a lisp file downloading and evaluating it"
(interactive "sEmacs lisp url to retrieve: ")
(switch-to-buffer (url-retrieve-synchronously url))
(goto-char (point-min))
(delete-region (point) (search-forward "\n\n" nil t)))
(defun unfill-region (beg end)
"Unfill the region, joining text paragraphs into a single
logical line. This is useful, e.g., for use with
(interactive "*r")
(let ((fill-column (point-max)))
(fill-region beg end)))
(define-key global-map "\C-\M-Q" 'unfill-region)
(defun my-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)))))))
; Emacswiki
(defun copy-line (arg)
"Copy lines (as many as prefix argument) in the kill ring"
(interactive "p")
(kill-ring-save (line-beginning-position)
(line-beginning-position (+ 1 arg)))
(message "%d line%s copied" arg (if (= 1 arg) "" "s")))
(define-key global-map (kbd "C-S-SPC") 'copy-line)
Jump to Line
Something went wrong with that request. Please try again.