legacy-dotfiles/.emacs.d/site-lisp/shift-indent.el
2012-08-18 13:19:27 +02:00

33 lines
1.1 KiB
EmacsLisp

(require 'simple)
(defun indent-shift-left (start end &optional count)
(interactive
(if mark-active
(list (region-beginning) (region-end) current-prefix-arg)
(list (line-beginning-position) (line-end-position) current-prefix-arg)))
(if count
(setq count (prefix-numeric-value count))
(setq count tab-width))
(when (> count 0)
(let ((deactivate-mark nil))
(save-excursion
(goto-char start)
(while (< (point) end)
(if (and (< (current-indentation) count)
(not (looking-at "[ \t]*$")))
(error "Can't shift all lines enough"))
(forward-line))
(indent-rigidly start end (- count))))))
(add-to-list 'debug-ignored-errors "^Can't shift all lines enough")
(defun indent-shift-right (start end &optional count)
(interactive
(if mark-active
(list (region-beginning) (region-end) current-prefix-arg)
(list (line-beginning-position) (line-end-position) current-prefix-arg)))
(let ((deactivate-mark nil))
(if count
(setq count (prefix-numeric-value count))
(setq count tab-width))
(indent-rigidly start end count)))