all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Rodolfo Medina <rodolfo.medina@gmail.com>
To: Konstantin Shakhnov <kastian@mail.ru>
Cc: help-gnu-emacs@gnu.org
Subject: [solved] Re: Indent first line of each paragraph of file in one hit
Date: Fri, 25 Nov 2016 15:39:09 +0000	[thread overview]
Message-ID: <87eg1z36xu.fsf_-_@gmail.com> (raw)
In-Reply-To: <20161125124539.GA12944@eee.birulevo.net> (Konstantin Shakhnov's message of "Fri, 25 Nov 2016 15:45:39 +0300")

Konstantin Shakhnov <kastian@mail.ru> writes:

> On Fri, Nov 25, 2016 at 12:20:45PM +0000, Rodolfo Medina wrote:
>> Konstantin Shakhnov <kastian@mail.ru> 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	other threads:[~2016-11-25 15:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24 15:35 Indent first line of each paragraph of file in one hit Rodolfo Medina
2016-11-24 22:44 ` Rodolfo Medina
2016-11-25 10:48 ` Konstantin Shakhnov
2016-11-25 11:28   ` Rodolfo Medina
2016-11-25 11:52     ` Rodolfo Medina
2016-11-25 12:15       ` Konstantin Shakhnov
2016-11-25 12:20         ` Rodolfo Medina
2016-11-25 12:45           ` Konstantin Shakhnov
2016-11-25 15:39             ` Rodolfo Medina [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eg1z36xu.fsf_-_@gmail.com \
    --to=rodolfo.medina@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=kastian@mail.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.