|
| 1 | +(defun comment-uncomment-line-or-region (&optional arg) |
| 2 | + "comments or uncomments a line according to state before. |
| 3 | +With key pressed, continues with next line. |
| 4 | +With arg copies and reinserts last line." |
| 5 | + (interactive "*P") |
| 6 | + (comment-normalize-vars) |
| 7 | + (let* ((arg (if arg (prefix-numeric-value arg) 0)) |
| 8 | + (start (if (and mark-active transient-mark-mode) |
| 9 | + (region-beginning) |
| 10 | + (line-beginning-position))) |
| 11 | + (end (if (and mark-active transient-mark-mode) |
| 12 | + (region-end) |
| 13 | + (line-end-position))) |
| 14 | + (line-to-comment-or-uncomment (buffer-substring-no-properties |
| 15 | + (or |
| 16 | + start (line-beginning-position)) |
| 17 | + (or end |
| 18 | + (line-end-position))))) |
| 19 | + (cond ((eq 1 arg) ;; comment and reinsert |
| 20 | + (comment-or-uncomment-region start end) |
| 21 | + (indent-according-to-mode) |
| 22 | + (end-of-line) |
| 23 | + (newline) |
| 24 | + (insert line-to-comment-or-uncomment) |
| 25 | + (indent-according-to-mode)) |
| 26 | + ((< 1 arg) ;; comment as many lines are given |
| 27 | + (while (<= 1 (prefix-numeric-value arg)) |
| 28 | + (comment-or-uncomment-region (line-beginning-position) |
| 29 | +(line-end-position)) |
| 30 | + (indent-according-to-mode) |
| 31 | + (end-of-line) |
| 32 | + (forward-line 1) |
| 33 | + ;; (indent-according-to-mode) |
| 34 | + (setq arg (1- arg)))) |
| 35 | + ((and start end) |
| 36 | + (comment-or-uncomment-region start end) |
| 37 | + (indent-according-to-mode) |
| 38 | + (if (eobp) |
| 39 | + (progn (newline) |
| 40 | + (indent-according-to-mode)) |
| 41 | + (progn |
| 42 | + (forward-line 1) |
| 43 | + (indent-according-to-mode)))) |
| 44 | + (t ;; just one line |
| 45 | + (progn (comment-or-uncomment-region (line-beginning-position) |
| 46 | +(line-end-position)) |
| 47 | + (indent-according-to-mode) |
| 48 | + (if (eobp) |
| 49 | + (progn (newline) |
| 50 | + (indent-according-to-mode)) |
| 51 | + (progn |
| 52 | + (forward-line 1) |
| 53 | + (indent-according-to-mode)))))))) |
| 54 | + |
| 55 | +(provide 'comment-uncomment-line-or-region) |
| 56 | +;;; comment-uncomment-line-or-region.el ends here |
| 57 | + |
| 58 | + |
| 59 | +(defun move-text-internal (arg) |
| 60 | + (cond |
| 61 | + ((and mark-active transient-mark-mode) |
| 62 | + (if (> (point) (mark)) |
| 63 | + (exchange-point-and-mark)) |
| 64 | + (let ((column (current-column)) |
| 65 | + (text (delete-and-extract-region (point) (mark)))) |
| 66 | + (forward-line arg) |
| 67 | + (move-to-column column t) |
| 68 | + (set-mark (point)) |
| 69 | + (insert text) |
| 70 | + (exchange-point-and-mark) |
| 71 | + (setq deactivate-mark nil))) |
| 72 | + (t |
| 73 | + (beginning-of-line) |
| 74 | + (when (or (> arg 0) (not (bobp))) |
| 75 | + (forward-line) |
| 76 | + (when (or (< arg 0) (not (eobp))) |
| 77 | + (transpose-lines arg)) |
| 78 | + (forward-line -1))))) |
| 79 | +(defun move-text-down (arg) |
| 80 | + "Move region (transient-mark-mode active) or current line |
| 81 | + arg lines down." |
| 82 | + (interactive "*p") |
| 83 | + (move-text-internal arg)) |
| 84 | +(defun move-text-up (arg) |
| 85 | + "Move region (transient-mark-mode active) or current line |
| 86 | + arg lines up." |
| 87 | + (interactive "*p") |
| 88 | + (move-text-internal (- arg))) |
| 89 | + |
| 90 | +;; function for transparency |
| 91 | +;;(set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>])) |
| 92 | +(set-frame-parameter (selected-frame) 'alpha '(85 50)) |
| 93 | +(add-to-list 'default-frame-alist '(alpha 85 50)) |
| 94 | +(eval-when-compile (require 'cl)) |
| 95 | +(defun toggle-transparency () |
| 96 | + (interactive) |
| 97 | + (if (/= |
| 98 | + (cadr (frame-parameter nil 'alpha)) |
| 99 | + 100) |
| 100 | + (set-frame-parameter nil 'alpha '(85 85)) |
| 101 | + (set-frame-parameter nil 'alpha '(85 50)))) |
| 102 | + |
0 commit comments