shosei

.emacs moving point direction

Feb 23rd, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.10 KB | None | 0 0
  1. ;; Moving point location
  2.  
  3. ;; don't add newlines to end of buffer when scrolling
  4. (setq next-line-add-newlines nil)
  5.  
  6. ;; XEmacs default for moving point to a given line number
  7. (GNUEmacs
  8.     (global-set-key (kbd "M-g") 'goto-line))
  9.  
  10. (global-set-key (kbd "M-G") 'what-line)
  11.  
  12. ;; move (shift) a line of text up or down like you would in Eclipse
  13. ;; press `M-up' (or `M-down')
  14. (defun move-line (n)
  15.   "Move the current line up or down by N lines."
  16.   (interactive "p")
  17.   (let ((col (current-column))
  18.         start
  19.         end)
  20.     (beginning-of-line)
  21.     (setq start (point))
  22.     (end-of-line)
  23.     (forward-char)
  24.     (setq end (point))
  25.     (let ((line-text (delete-and-extract-region start end)))
  26.       (forward-line n)
  27.       (insert line-text)
  28.       ;; restore point to original column in moved line
  29.       (forward-line -1)
  30.       (forward-char col))))
  31.  
  32. (defun move-line-up (n)
  33.   "Move the current line up by N lines."
  34.   (interactive "p")
  35.   (move-line (if (null n) -1 (- n))))
  36.  
  37. (defun move-line-down (n)
  38.   "Move the current line down by N lines."
  39.   (interactive "p")
  40.   (move-line (if (null n) 1 n)))
Advertisement
Add Comment
Please, Sign In to add comment