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

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

Re: [solved] Re: To switch state of line not working


From: Jean Louis
Subject: Re: [solved] Re: To switch state of line not working
Date: Tue, 15 Jun 2021 06:02:06 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> [2021-06-15 05:58]:
> Jean Louis wrote:
> 
> >> > (or check-in  (or rcd-check-in-default  "[ ]"))
> >> > (or check-out (or rcd-check-out-default "[✔]"))
> >> 
> >> (or nil nil 1) ; 1
> >
> > Yes, why not, maybe the optional check-in, maybe the global
> > one, if none is there the hard coded one...
> 
> Yes, that made/makes sense, but no need to nest `or', I mean.

"n'or" any more, no or any more...

(defvar rcd-check-in "❰    ❱")
(defvar rcd-check-out "❰DONE❱")

(defun rcd-check ()
  "Replace matches of CHECK-IN with CHECK-OUT in a line.

It is useful to toggle [ ] to [✔]"
  (interactive)
  (let* ((start (line-beginning-position))
         (end (line-end-position))
         (line (buffer-substring start end)))
    (rcd-check-start)
    (save-excursion
      (cond ((string-match (regexp-quote rcd-check-in) line) 
             (replace-regexp (regexp-quote rcd-check-in) rcd-check-out nil 
start end))
            ((string-match (regexp-quote rcd-check-out) line)
             (replace-regexp (regexp-quote rcd-check-out) rcd-check-in nil 
start end))))))

(defun rcd-check-start ()
  "Insert variable `rcd-check-in' at the beginning of line."
  (interactive)
  (let* ((start (line-beginning-position))
         (end (line-end-position))
         (line (buffer-substring start end)))
    (when (and (not (string-match rcd-check-in line))
               (not (string-match rcd-check-out line)))
      (save-excursion
        (goto-char start)
        (insert rcd-check-in " "))
      (when (= start end)
        (goto-char (line-end-position))))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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