help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[solved] Re: Indent first line of each paragraph of file in one hit


From: Rodolfo Medina
Subject: [solved] Re: Indent first line of each paragraph of file in one hit
Date: Fri, 25 Nov 2016 15:39:09 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Konstantin Shakhnov <address@hidden> writes:

> On Fri, Nov 25, 2016 at 12:20:45PM +0000, Rodolfo Medina wrote:
>> Konstantin Shakhnov <address@hidden> writes:
>> > Yes, I've just made something similar. But there is a trap - if your
>> > file doesn't starts with '\n' you'll get wrong indentation of the
>> > first paraghaph
>> Yes, I see.  No way to avoid that?
>
> (defun my-indent-first-line ()
>   "Indent the first line of current paragraph"
>   (interactive)
>   (backward-paragraph)
>   (if (= (line-beginning-position) (line-end-position)) ; if line not empty
>       (next-line))
>   (insert ">>>>")
>   (fill-paragraph))
>
> Not very nice, but seems working.


Thanks!  Константин also provided this:

(defun my-indent-first-line-of-all-paragraphs ()
  "Indent the first line of each paragraph"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (not (= (point) (point-max)))
      (if (= (line-beginning-position) (line-end-position)) ; if empty line
          (next-line))
      (insert ">>>>")
      (fill-paragraph)
      (forward-paragraph))))

(global-set-key (kbd "C-c i") 'my-indent-all-paragraphs)

(defun my-indent-first-line-of-current-paragraph ()
  "Indent the first line of current paragraph"
  (interactive)
  (backward-paragraph)
  (if (= (line-beginning-position) (line-end-position))
      (next-line))
  (insert ">>>>")
  (fill-paragraph))

(global-set-key (kbd "M-p") 'my-indent-first-line)


Thanks to all for these splendid solutions.

Cheers,

Rodolfo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]