(defun delete-indentation (&optional arg) "Join this line to previous and fix up whitespace at join. If there is a fill prefix, delete it from the beginning of this line. With argument, join this line to following line." (interactive "*P") (let ((return-point (point)) (return-col (if (not arg) (- (point-at-eol) (point))))) (beginning-of-line) (if arg (forward-line 1)) (if (eq (preceding-char) ?\n) (progn (delete-region (point) (1- (point))) ;; If the second line started with the fill prefix, ;; delete the prefix. (if (and fill-prefix (<= (+ (point) (length fill-prefix)) (point-max)) (string= fill-prefix (buffer-substring (point) (+ (point) (length fill-prefix))))) (delete-region (point) (+ (point) (length fill-prefix)))) (fixup-whitespace) (if return-col (goto-char (- (point-at-eol) return-col)) (goto-char return-point)))))) (defun my-join-lines (&optional arg) "Join multiple lines, forward or backwards. By default, joins forward one line (the standard `join-lines', an alias for `delete-indentation', and bound by default to M-^, joins backward by default). With a prefix argument joins that number of lines in +/- direction. With a region selected, joins all lines in the region." (interactive "p") (let ((return-point (point)) ; ┃ return-col) ; ┃ (if (use-region-p) (let ((begin (region-beginning))) (when (= (point) (region-end)) ; ┃ (setq return-col (- (point-at-eol) (point)))) ; ┃ (goto-char (region-end)) (while (> (point-at-bol) begin) (join-line))) (if arg (if (> arg 0) (dotimes (i arg) (join-line t)) (setq return-col (- (point-at-eol) (point))) ; ┃ (dotimes (i (- 0 arg)) (join-line))) (join-line t))) (if return-col ; ┃ (goto-char (- (point-at-eol) return-col)) ; ┃ (goto-char return-point)))) ; ┃