Anonymous committed 551dc1b

* Added lots of functions to defuns-edit.el
* Overhaul of movement keybinds (and others)
* Added mc/mark-all-like-this-dwim
* Fixed sr-tabs binding of C-p/n, moved to C-P/N
* Added maximize-frame on startup

  • Participants
  • Parent commits e59c4ab

Comments (0)

Files changed (7)

 (setq mc/cmds-to-run-for-all
+        beginning-of-region
+        end-of-region
+        mc/mark-all-like-this-dwim


 ;; line selection functions
-(defun select-line ()
+(defun line-select ()
   "Set the active region to current line"
   (set-mark (point))
-(defun select-to-the-beginning-of-line ()
+(defun beginning-of-line-select ()
+  "Set the active region from beginning of current line to the point"
   (set-mark (point))
-(defun select-to-the-end-of-line ()
+(defun end-of-line-select ()
+  "Set the active region from point to the end of current line"
   (set-mark (point))
     (next-line 1)
+(defun forward-paragraph-select ()
+  "Set the active region from point to end of current paragraph"
+  (interactive)
+  (set-mark (point))
+  (forward-paragraph))
+(defun backward-paragraph-select ()
+  "Set the active region from point to beginning of current paragraph"
+  (interactive)
+  (set-mark (point))
+  (backward-paragraph))
+(defun beginning-of-region ()
+  "Move cursor to the beginning of active region"
+  (interactive)
+  (goto-char (region-beginning)))
+(defun end-of-region ()
+  "Move cursor to the end of active region"
+  (interactive)
+  (goto-char (region-end)))
+(defun backward-up-list+ ()
+  "Same as backward-up-list, but can also move out from withing a string"
+  (interactive)
+  (if (in-string-p)
+      (while (in-string-p)
+        (backward-char))
+    (backward-up-list)))
+(defun up-list+ ()
+  "Same as up-list, but can also move out from withing a string"
+  (interactive)
+  (if (in-string-p)
+      (while (in-string-p)
+        (forward-char))
+    (up-list)))
 (defun copy-line ()
-  "Copy line to the kill ring but restore it afterwards"
+  "Copy line (from point to end) to the kill ring but restore it afterwards"
-  (let ((x (point)))
-    (kill-line)
-    (yank)
-    (goto-char x)))
+  (save-excursion
+    (let ((x (point)))
+      (kill-line)
+      (yank)
+      (goto-char x))))
 (defun eval-and-replace ()
   "Replace the preceding sexp with its value."
 (defun copy-next-line ()
   (copy-line-with-offset 1))
+(defun mc/mark-all-like-this-dwim (arg)
+  "Find and mark all the parts of current defun matchign the
+currently active region. With prefix, mark occurences in whole buffer."
+  (interactive "P")
+  (if arg
+      (mc/mark-all-like-this)
+    (if (bounds-of-thing-at-point 'defun)
+        (save-excursion
+          (save-restriction
+            (narrow-to-defun)
+            (mc/mark-all-like-this)))
+      (mc/mark-all-like-this))))
 ;; buffer cleanup
 (global-set-key (kbd "C-c n") 'cleanup-buffer)
-; buffer switching
-(global-set-key (kbd "M-]") 'previous-buffer)
-(global-set-key (kbd "M-\\") 'next-buffer)
 ;; Window navigation
 (windmove-default-keybindings 'meta)
 (global-unset-key (kbd "M-.")) ;; was Find tag
 (global-set-key (kbd "M-.") 'ido-goto-symbol)
-;; jump to beginning/end of the file
-(global-unset-key [(home)]) ;; was C-a
-(global-unset-key [(end)]) ;; was C-e
-(global-set-key [(home)] 'beginning-of-buffer)
-(global-set-key [(end)] 'end-of-buffer)
+;; sexp settings
+(global-set-key (kbd "C-c C-e") 'eval-and-replace)
-;; line selection
-(global-set-key (kbd "H-e") 'select-to-the-end-of-line)
-(global-set-key (kbd "H-a") 'select-to-the-beginning-of-line)
-(global-set-key (kbd "H-s") 'select-line)
+(global-set-key (kbd "M-y") 'helm-show-kill-ring)
-(global-unset-key (kbd "C-v"))
-(global-set-key (kbd "C-v") 'copy-line)
-(global-set-key (kbd "C-c <up>") 'copy-previous-line)
-(global-set-key (kbd "C-c <down>") 'copy-next-line)
+;; navigation
+;; remove arrows, evil!
+(mapc 'global-unset-key [[up] [down] [left] [right]])
+;; # move by (forw/back)
+;; character
+(global-set-key (kbd "C-f") 'forward-char)
+(global-set-key (kbd "C-b") 'backward-char)
+;; word
+(global-set-key (kbd "M-f") 'forward-word)
+(global-set-key (kbd "M-b") 'backward-word)
+;; line
+(global-set-key (kbd "C-n") 'next-line)
+(global-set-key (kbd "C-p") 'previous-line)
+;; sentence
+(global-set-key (kbd "M-a") 'forward-sentence)
+(global-set-key (kbd "M-e") 'backward-sentence)
+;; paragraph
+(global-unset-key (kbd "M-{")) ;; was backward-paragraph
+(global-unset-key (kbd "M-}")) ;; was forward-paragraph
+(global-set-key (kbd "M-[") 'backward-paragraph)
+(global-set-key (kbd "M-]") 'forward-paragraph)
+(global-set-key (kbd "M-{") 'backward-paragraph-select)
+(global-set-key (kbd "M-}") 'forward-paragraph-select)
+;; screen
+(global-set-key (kbd "C-v") 'scroll-down-command)
+(global-set-key (kbd "M-v") 'scroll-up-command)
+;; sexp
+(global-set-key (kbd "C-M-f") 'forward-sexp)
+(global-set-key (kbd "C-M-b") 'backward-sexp)
+;; list
+(global-set-key (kbd "C-M-n") 'forward-list)
+(global-set-key (kbd "C-M-p") 'backward-list)
+;; # move to (beg/end)
+;; line
 ;; swap C-a and M-m, back-to-indentation is much more common
 (global-unset-key (kbd "M-m"))
 (global-unset-key (kbd "C-a"))
 (global-set-key (kbd "M-m") 'beginning-of-line)
 (global-set-key (kbd "C-a") 'back-to-indentation)
+(global-set-key (kbd "C-e") 'end-of-line)
+;; buffer
+(global-unset-key [(home)]) ;; was C-a
+(global-unset-key [(end)]) ;; was C-e
+(global-set-key (kbd "M-<") 'beginning-of-buffer)
+(global-set-key (kbd "M->") 'end-of-buffer)
+;; defun
+(global-set-key (kbd "M-p") 'beginning-of-defun)
+(global-set-key (kbd "M-n") 'end-of-defun)
+;; active region
+(global-set-key (kbd "C-c a") 'beginning-of-region)
+(global-set-key (kbd "C-c e") 'end-of-region)
-;; sexp settings
-(global-set-key (kbd "C-M-a") 'backward-sexp)
-(global-set-key (kbd "C-M-e") 'forward-sexp)
-(global-set-key (kbd "C-c C-e") 'eval-and-replace)
+;; # move into
+(global-set-key (kbd "C-M-d") 'down-list)
+(global-set-key (kbd "C-M-e") 'up-list+)
+(global-set-key (kbd "C-M-u") 'backward-up-list+)
-(global-set-key (kbd "M-y") 'helm-show-kill-ring)
+;; line selection
+(global-set-key (kbd "H-a") 'beginning-of-line-select)
+(global-set-key (kbd "H-e") 'end-of-line-select)
+(global-set-key (kbd "H-s") 'line-select)
+(global-set-key (kbd "H-w") 'copy-line)
+(global-set-key (kbd "C-c <up>") 'copy-previous-line)
+(global-set-key (kbd "C-c <down>") 'copy-next-line)
 ;; opening new lines. C-o can be called from any point on the line
 ;; ret from the end only
 (global-set-key (kbd "RET") 'open-next-line)
 (global-set-key (kbd "C-o") 'vi-open-next-line)
+;; go to char, also mapped to a keychord df
 (global-set-key (kbd "C-c f") 'iy-go-to-char)
 (global-set-key (kbd "C-c F") 'iy-go-to-char-backward)
 (global-set-key (kbd "C-c ;") 'iy-go-to-char-continue)
 (global-set-key (kbd "C-c ,") 'iy-go-to-char-continue-backward)
 ;; keys for specific modes
 (defun add-html-binding ()
   (define-key (current-local-map) (kbd "C-c <deletechar>") 'sgml-delete-tag))
   (add-hook hook 'add-html-binding))
+;; sunrise
 (global-set-key [(f1)] 'sunrise)
 (global-set-key [(meta f1)] 'sunrise-cd)


 (global-set-key (kbd "s-.") 'mc/mark-next-like-this)
 (global-set-key (kbd "s-,") 'mc/mark-previous-like-this)
 (global-set-key (kbd "s-\\") 'mc/mark-more-like-this-extended)
-(global-set-key (kbd "s-/") 'mc/mark-all-like-this)
+(global-set-key (kbd "s-/") 'mc/mark-all-like-this-dwim)
 ;; From active region to multiple cursors:


 (require 'sunrise-x-tabs)
 (require 'sunrise-x-w32-addons)
+(define-key sr-tabs-mode-map [(control ?p)] nil)
+(define-key sr-tabs-mode-map [(control ?n)] nil)
+(define-key sr-tabs-mode-map [(control ?P)] 'sr-tabs-prev)
+(define-key sr-tabs-mode-map [(control ?N)] 'sr-tabs-next)
 (defun my-sunrise-init ()
   (define-key sr-mode-map [(backspace)] 'sr-dired-prev-subdir)
   (define-key sr-mode-map (kbd "M-\r") 'dired-w32-browser)
 (menu-bar-mode -1)
 (tool-bar-mode -1)
 (tooltip-mode -1)
+;; maximize window at startup
+(defun maximize-frame ()
+  "Maximizes the active frame in Windows"
+  (interactive)
+  ;; Send a `WM_SYSCOMMAND' message to the active frame with the
+  ;; `SC_MAXIMIZE' parameter.
+  (when (eq system-type 'windows-nt)
+    (w32-send-sys-command 61488)))
+(add-hook 'window-setup-hook 'maximize-frame t)
 ;; add load paths
 (add-to-list 'load-path "~/.emacs.d")


   (setq mc/keymap (make-sparse-keymap))
   (define-key mc/keymap (kbd "C-g") 'mc/keyboard-quit)
-  (define-key mc/keymap (kbd "C-c e") 'mc/goto-end-of-region)
-  (define-key mc/keymap (kbd "C-c a") 'mc/goto-beginning-of-region)
   (define-key mc/keymap (kbd "<return>") 'multiple-cursors-mode))
-(defun mc/goto-beginning-of-region ()
-  (interactive)
-  (goto-char (region-beginning)))
-(defun mc/goto-end-of-region ()
-  (interactive)
-  (goto-char (region-end)))
 (defun mc--all-equal (entries)
   "Are all these entries equal?"
   (let ((first (car entries))