Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.emacs global-set-key and calling interactive function with argument

Tags:

emacs

elisp

In my .emacs i have the following function that transposes a line

(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)))) 

And I bind a key to it like this

(global-set-key (kbd "M-<down>") 'move-line) ;; this is the same as M-x global-set-key <return> 

However, I want to bind M-up to move-line (-1) But I cant seem to be able to do it correctly:

;; M-- M-1 M-x global-set-key <return> 

How do I define the above using global-set-key to call move-line -1?

like image 847
yrral Avatar asked Jun 23 '09 02:06

yrral


1 Answers

Not minutes after asking the question I figured it out by copy+pasting code. However I have no clue how it works.

(global-set-key (kbd "M-<up>") (lambda () (interactive) (move-line -1))) 
like image 183
yrral Avatar answered Sep 23 '22 19:09

yrral