Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

243 lines (211 sloc) 7.969 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)
(isearch-search-and-update))
(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))
(yank)
(goto-char p)))
(defun my-duplicate-line-or-region ()
"duplicate the region if active otherwise the current line"
(interactive)
(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()
(interactive)
(let ((col (current-column)))
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(forward-char col)
)
)
(defun my-up-line()
(interactive)
(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")
(beginning-of-line)
(open-line arg)
(when newline-and-indent
(indent-according-to-mode)))
(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)
(progn
(save-excursion
(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.
;http://omniorthogonal.blogspot.com/2008/05/useful-emacs-dired-launch-hack.html
(defun my-dired-launch-command ()
(interactive)
(dired-do-shell-command
(case system-type
(gnu/linux "gnome-open") ;right for gnome (ubuntu), not for other systems
(darwin "open"))
nil
(dired-get-marked-files t current-prefix-arg)))
;; Remap goto-line to show temporary the line number.
;; http://whattheemacsd.com//key-bindings.el-01.html
(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"
(interactive)
(unwind-protect
(progn
(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 ()
(interactive)
(move-end-of-line nil)
(newline-and-indent))
(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 ()
(interactive)
(kill-line 0)
(indent-according-to-mode)))
;Kill whole line but stay at the same place.
(global-set-key (kbd "C-S-k") (lambda ()
(interactive)
(let ((p (point)))
(kill-whole-line)
(goto-char p))))
; https://github.com/jedrz/.emacs.d/blob/master/defuns/misc-defuns.el
(defun my-hippie-expand-lines ()
"Try to expand entire line."
(interactive)
(let ((hippie-expand-try-functions-list '(try-expand-line
try-expand-line-all-buffers)))
(hippie-expand nil)))
(global-set-key (kbd "C-?") 'my-hippie-expand-lines)
;http://emacsredux.com/blog/2013/05/30/joining-lines/
(defun my-top-join-line ()
"Join the current line with the line beneath it."
(interactive)
(delete-indentation 1))
(global-set-key (kbd "C-S-j") 'my-top-join-line)
;http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-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)))
(back-to-indentation)
(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 http://www.emacswiki.org/emacs/FullScreen#toc23
(defun my-toggle-fullscreen ()
"Toggle full screen"
(interactive)
(set-frame-parameter
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: ")
(progn
(switch-to-buffer (url-retrieve-synchronously url))
(save-excursion
(goto-char (point-min))
(delete-region (point) (search-forward "\n\n" nil t)))
(eval-current-buffer)
(emacs-lisp-mode)
(font-lock-fontify-buffer)))
;http://www.emacswiki.org/emacs/UnfillRegion
(defun unfill-region (beg end)
"Unfill the region, joining text paragraphs into a single
logical line. This is useful, e.g., for use with
`visual-line-mode'."
(interactive "*r")
(let ((fill-column (point-max)))
(fill-region beg end)))
(define-key global-map "\C-\M-Q" 'unfill-region)
;https://github.com/milkypostman/dotemacs/blob/master/init.el
(defun my-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)))))))
; 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.