89 lines
2.9 KiB
EmacsLisp
89 lines
2.9 KiB
EmacsLisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; FUNCTIONS
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;==============================================================================
|
|
;; Unfill paragraph
|
|
;;==============================================================================
|
|
|
|
(defun unfill-paragraph ()
|
|
(interactive)
|
|
(let ((fill-column (point-max)))
|
|
(fill-paragraph nil)))
|
|
|
|
(defun unfill-region ()
|
|
(interactive)
|
|
(let ((fill-column (point-max)))
|
|
(fill-region (region-beginning) (region-end) nil)))
|
|
|
|
;; Remove duplicate lines. (sort -u)
|
|
;; TODO: finish it.
|
|
(defun remove-duplicates ()
|
|
(interactive)
|
|
((shell-command (echo blah)))
|
|
)
|
|
|
|
;;==============================================================================
|
|
;; Duplicate line
|
|
;;==============================================================================
|
|
(defun duplicate-line (arg)
|
|
"Duplicate current line, leaving point in lower line."
|
|
(interactive "*p")
|
|
|
|
;; save the point for undo
|
|
(setq buffer-undo-list (cons (point) buffer-undo-list))
|
|
|
|
;; local variables for start and end of line
|
|
(let ((bol (save-excursion (beginning-of-line) (point)))
|
|
eol)
|
|
(save-excursion
|
|
|
|
;; don't use forward-line for this, because you would have
|
|
;; to check whether you are at the end of the buffer
|
|
(end-of-line)
|
|
(setq eol (point))
|
|
|
|
;; store the line and disable the recording of undo information
|
|
(let ((line (buffer-substring bol eol))
|
|
(buffer-undo-list t)
|
|
(count arg))
|
|
;; insert the line arg times
|
|
(while (> count 0)
|
|
(newline) ;; because there is no newline in 'line'
|
|
(insert line)
|
|
(setq count (1- count)))
|
|
)
|
|
|
|
;; create the undo information
|
|
(setq buffer-undo-list (cons (cons eol (point)) buffer-undo-list)))
|
|
) ; end-of-let
|
|
|
|
;; put the point in the lowest line and return
|
|
(next-line arg))
|
|
|
|
;; Binding.
|
|
(define-key my-keys-minor-mode-map (kbd "C-c C-d") 'duplicate-line)
|
|
|
|
;;==============================================================================
|
|
;; Comment DWIM -- toggle comment line
|
|
;;==============================================================================
|
|
|
|
;; Original idea from
|
|
;; http://www.opensubscriber.com/message/emacs-devel@gnu.org/10971693.html
|
|
(defun comment-dwim-line (&optional arg)
|
|
"Replacement for the comment-dwim command. If no region is
|
|
selected and current line is not blank and we are not at the end
|
|
of the line, then comment current line. Replaces default
|
|
behaviour of comment-dwim, when it inserts comment at the end of
|
|
the line."
|
|
(interactive "*P")
|
|
(comment-normalize-vars)
|
|
;; (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
|
|
(if (and (not (region-active-p)) )
|
|
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
|
|
(comment-dwim arg)))
|
|
|
|
;; Binding.
|
|
;; TODO: global key ?
|
|
(global-set-key "\M-;" 'comment-dwim-line)
|