Add move-live package

This commit is contained in:
Gergely Polonkai 2014-10-05 16:26:52 +02:00
parent fb29d3b591
commit 20bf94ef4f
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,18 @@
;;; move-line-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
;;;### (autoloads nil nil ("move-line-pkg.el" "move-line.el") (21553
;;;;;; 16742 574441 73000))
;;;***
(provide 'move-line-autoloads)
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; move-line-autoloads.el ends here

View File

@ -0,0 +1 @@
(define-package "move-line" "0.0.1" "utilities for moving lines in file" (quote nil))

View File

@ -0,0 +1,73 @@
;;; move-line.el --- utilities for moving lines in file
;; Copyright (C) 2014 Nathaniel Flath <flat0103@gmail.com>
;; Author: Nathaniel Flath <flat0103@gmail.com>
;; URL: http://github.com/nflath/move-line
;; Version: 0.0.1
;; This file is not part of GNU Emacs.
;;; Commentary:
;; This file provides several utility functions for moving the current line
;; up/down. The functions provided are move-line-up and move-line-down, bound
;; to control-shift-up and control-shift-down by default.
;;; Installation
;; To use this mode, put the following in your init.el:
;; (require 'move-line)
;;; License:
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(defun move-line (n)
"Move the current line up or down by N lines."
(interactive "p")
(let ((col (current-column))
start
end)
(beginning-of-line)
(setq start (point))
(end-of-line)
(forward-char)
(setq end (point))
(let ((line-text (delete-and-extract-region start end)))
(forward-line n)
(insert line-text)
;; restore point to original column in moved line
(forward-line -1)
(forward-char col))))
(defun move-line-up (n)
"Move the current line up by N lines."
(interactive "p")
(move-line (if (null n) -1 (- n))))
(defun move-line-down (n)
"Move the current line down by N lines."
(interactive "p")
(move-line (if (null n) 1 n)))
(global-set-key [(control shift up)] 'move-line-up)
(global-set-key [(control shift down)] 'move-line-down)
(provide 'move-line)
;;; move-line.el ends here