all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: To switch state of line not working
Date: Tue, 15 Jun 2021 03:07:39 +0200	[thread overview]
Message-ID: <87r1h42aw4.fsf@zoho.eu> (raw)
In-Reply-To: courier.0000000060C7EF50.00002640@stw1.rcdrun.com

Jean Louis wrote:

> 1. [ ] Something to do
> 2. [ ] More to do
> 3. [✔] And more
> 4. [✔] Even more.
>
> This function below is supposed to switch from [✔] to [ ] when cursor
> is on the line but it is not working. It is switching only from [ ] to
> [✔].  Does somebody sees why?
>
> (defun rcd-check (&optional check-in check-out)
>   (interactive)
>   (let* ((start (line-beginning-position))
> 	 (end (line-end-position))
> 	 (line (buffer-substring start end))
> 	 (check-in (or check-in (regexp-quote "[ ]")))
> 	 (check-out (or check-out (regexp-quote "[✔]"))))
>     (if (string-match check-in line)
> 	(progn
> 	  (replace-line check-in check-out))
>       (if (string-match check-out line)
> 	  (progn
> 	    (replace-line check-out check-in))))))

name: "start" -> "beg" for nice align with "end".

first `if' - no need for `progn'.

second if - ditto, also here use `when' instead.

> (defun replace-line (from to)
>   (let* ((start (line-beginning-position))
> 	 (end (line-end-position))
> 	 (line (buffer-substring start end)))
>     (save-excursion
>       (replace-string from to nil start end))))

`replace-string' should be `search-forward' and
`replace-match'.

And you are not using "line"!

Also try `buffer-substring-no-properties' if the above
doesn't help.

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2021-06-15  1:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15  0:07 To switch state of line not working Jean Louis
2021-06-15  1:07 ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2021-06-15  1:16   ` Jean Louis
2021-06-15  1:31     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  1:30 ` [solved] " Jean Louis
2021-06-15  1:45   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  1:48     ` Jean Louis
2021-06-15  1:48     ` Jean Louis
2021-06-15  2:00       ` Jean Louis
2021-06-15  2:11         ` Jean Louis
2021-06-15  2:34           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  2:38             ` Jean Louis
2021-06-15  3:02               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  3:05                 ` Jean Louis
2021-06-15  3:12                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  2:42             ` Jean Louis
2021-06-15  2:57               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  3:02                 ` Jean Louis
2021-06-15  3:09                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  1:45   ` Jean Louis
2021-06-15  2:22     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  2:25       ` Jean Louis
2021-06-15  2:37         ` Emanuel Berg via Users list for the GNU Emacs text editor

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=87r1h42aw4.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /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.