Skip to content

Commit

Permalink
added changes by Bastian
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielelanaro committed Jun 11, 2011
1 parent 3f2837d commit 8721ed4
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions epy-python.el
Expand Up @@ -96,4 +96,126 @@ The CMDLINE should be something like:
(add-to-list 'auto-mode-alist '("\\.pxd\\'" . cython-mode))
(add-to-list 'auto-mode-alist '("\\.pxi\\'" . cython-mode))

(add-hook 'python-mode-hook '(lambda ()
(define-key python-mode-map "\C-m" 'newline-and-indent)))

;; code borrowed from http://emacs-fu.blogspot.com/2010/01/duplicating-lines-and-commenting-them.html
(defun djcb-duplicate-line (&optional commentfirst)
"comment line at point; if COMMENTFIRST is non-nil, comment the
original" (interactive)
(beginning-of-line)
(push-mark)
(end-of-line)
(let ((str (buffer-substring (region-beginning) (region-end))))
(when commentfirst
(comment-region (region-beginning) (region-end)))
(insert-string
(concat (if (= 0 (forward-line 1)) "" "\n") str "\n"))
(forward-line -1)))

;; duplicate a line
(global-set-key (kbd "C-c y") 'djcb-duplicate-line)

;; duplicate a line and comment the first
(global-set-key (kbd "C-c c")
(lambda()(interactive)(djcb-duplicate-line t)))



; code copied from http://stackoverflow.com/questions/2423834/move-line-region-up-and-down-in-emacs
(defun move-text-internal (arg)
(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)
(when (or (< arg 0) (not (eobp)))
(transpose-lines arg))
(forward-line -1))
(move-to-column column t)))))

(defun move-text-down (arg)
"Move region (transient-mark-mode active) or current line
arg lines down."
(interactive "*p")
(move-text-internal arg))

(defun move-text-up (arg)
"Move region (transient-mark-mode active) or current line
arg lines up."
(interactive "*p")
(move-text-internal (- arg)))

; patches by balle
; http://www.datenterrorist.de
(defun balle-python-shift-left ()
(interactive)
(let (start end bds)
(if (and transient-mark-mode
mark-active)
(setq start (region-beginning) end (region-end))
(progn
(setq bds (bounds-of-thing-at-point 'line))
(setq start (car bds) end (cdr bds))))
(python-indent-shift-left start end))
(setq deactivate-mark nil)
)

(defun balle-python-shift-right ()
(interactive)
(let (start end bds)
(if (and transient-mark-mode
mark-active)
(setq start (region-beginning) end (region-end))
(progn
(setq bds (bounds-of-thing-at-point 'line))
(setq start (car bds) end (cdr bds))))
(python-indent-shift-right start end))
(setq deactivate-mark nil)
)

(global-set-key (kbd "C-c <up>") 'move-text-up)
(global-set-key (kbd "C-c <down>") 'move-text-down)

;; Cua mode special case for move-text-up/down
(add-hook 'cua-mode-hook
(lambda ()
(define-key cua-global-keymap (kbd "M-<up>") 'move-text-up)
(define-key cua-global-keymap (kbd "M-<down>") 'move-text-down)
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map (kbd "M-<right>")
'balle-python-shift-right)
(define-key python-mode-map (kbd "M-<left>")
'balle-python-shift-left))
)
)
)


(global-set-key [f10] 'flymake-goto-prev-error)
(global-set-key [f11] 'flymake-goto-next-error)

;; Indenting-dedenting regions
(add-hook 'python-mode-hook
(lambda ()
(unless (equal cua-mode t)
(define-key python-mode-map (kbd "C-c <right>")
'balle-python-shift-right)
(define-key python-mode-map (kbd "C-c <left>")
'balle-python-shift-left))
))

(provide 'epy-python)

0 comments on commit 8721ed4

Please sign in to comment.