emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 10/35: Add moving lines/region using M-up or M-down. Issue #266


From: Matthew Fidler
Subject: [elpa] 10/35: Add moving lines/region using M-up or M-down. Issue #266
Date: Fri, 11 Jul 2014 22:33:22 +0000

mlf176f2 pushed a commit to branch externals/ergoemacs-mode
in repository elpa.

commit cc31671b06a1710045a979cd976d1218ed7ff4c8
Author: Matthew L. Fidler <address@hidden>
Date:   Mon Jul 7 09:57:24 2014 -0500

    Add moving lines/region using M-up or M-down. Issue #266
---
 ergoemacs-functions.el |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 ergoemacs-themes.el    |    9 +++++++--
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el
index 1e23f62..93bff61 100644
--- a/ergoemacs-functions.el
+++ b/ergoemacs-functions.el
@@ -4,7 +4,7 @@
 
 ;; Maintainer: Matthew L. Fidler
 ;; Authors: Xah Lee, Matthew Fidler, Drew Adams, Ting-Yu Lin, David
-;; Capello, Nikolaj Schumacher
+;; Capello, Nikolaj Schumacher, Andy Stewart
 ;; Keywords: convenience
 
 ;; ErgoEmacs is free software: you can redistribute it and/or modify
@@ -2199,6 +2199,51 @@ See also `ergoemacs-lookup-word-on-internet'."
   (let ((apropos-do-all nil))
     (apropos-variable regexp)))
 
+(defun ergoemacs-move-text-internal (arg)
+  "Move region (transient-mark-mode active) or current line."
+  ;; From Andy Stewart, who signed the gnu emacs license since he has
+  ;; components within gnu emacs.
+  ;; See `http://www.emacswiki.org/emacs/basic-edit-toolkit.el'
+  (let ((remember-point (point)))
+    ;; Can't get correct effect of `transpose-lines'
+    ;; when `point-max' is not at beginning of line
+    ;; So fix this bug.
+    (goto-char (point-max))
+    (if (not (bolp)) (newline))         ;add newline to fix
+    (goto-char remember-point)
+    ;; logic code start
+    (cond ((and mark-active transient-mark-mode)
+           (if (> (point) (mark))
+               (exchange-point-and-mark))
+           (let ((column (current-column))
+                 (text (delete-and-extract-region (point) (mark))))
+             (forward-line arg)
+             (move-to-column column t)
+             (set-mark (point))
+             (insert text)
+             (exchange-point-and-mark)
+             (setq deactivate-mark nil)))
+          (t
+           (let ((column (current-column)))
+             (beginning-of-line)
+             (when (or (> arg 0) (not (bobp)))
+               (forward-line 1)
+               (when (or (< arg 0) (not (eobp)))
+                 (transpose-lines arg))
+               (forward-line -1))
+             (move-to-column column t))))))
+
+(defun ergoemacs-move-text-up (arg)
+  "Move region (transient-mark-mode active) or current line ARG lines up."
+  (interactive "*p")
+  (ergoemacs-move-text-internal (- arg)))
+
+(defun ergoemacs-move-text-down (arg)
+  "Move region (transient-mar-mode active) or current line (ARG lines) down."
+  (interactive "*p")
+  (ergoemacs-move-text-internal arg))
+
+
 (defvar ergoemacs-shortcut-keys)
 (defvar ergoemacs-no-shortcut-keys)
 (defvar ergoemacs-read-input-keys)
diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el
index b0f61f3..f6e9254 100644
--- a/ergoemacs-themes.el
+++ b/ergoemacs-themes.el
@@ -580,6 +580,11 @@
   (define-key eshell-mode-map (kbd "M-h") 'eshell-bol)
   (define-key comint-mode-map (kbd "M-H") 'comint-bol))
 
+(ergoemacs-theme-component move-and-transpose-lines ()
+  "Move Current line/selection down or up with Alt+up or Alt+down"
+  (global-set-key [\M-up] 'ergoemacs-move-text-up)
+  (global-set-key [\M-down] 'ergoemacs-move-text-down))
+
 (ergoemacs-theme-component move-page ()
   "Move by Page"
   (global-unset-key (kbd "M-v"))
@@ -1103,7 +1108,7 @@
                   ("Function Keys" (fn-keys f2-edit))
                   ("Remaps" (ido-remaps helm-remaps multiple-cursors-remaps))
                   ("Extreme ErgoEmacs" (guru no-backspace 
ergoemacs-banish-shift))
-                  ("Standard Keys" (standard-fixed fixed-bold-italic quit))
+                  ("Standard Keys" (standard-fixed fixed-bold-italic quit 
move-and-transpose-lines))
                   ("Keys during Key Sequence" (f2-edit apps-swap 
backspace-del-seq))))
 
 (ergoemacs-theme reduction ()
@@ -1144,7 +1149,7 @@
                  apps-swap
                  save-options-on-exit)
   :optional-off '(guru no-backspace search-reg
-                       ergoemacs-banish-shift)
+                       ergoemacs-banish-shift move-and-transpose-lines)
   :options-menu '(("Menu/Apps Key" (apps apps-apps apps-punctuation))
                   ("Function Keys" (fn-keys f2-edit))
                   ("Remaps" (ido-remaps helm-remaps multiple-cursors-remaps))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]