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 04:45:56 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

Shorter version:
n
(defun rcd-check (&optional check-in check-out)
  "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))
         (check-in (or check-in "[ ]"))
         (check-out (or check-out "[✔]")))
    (cond ((string-match (regexp-quote check-in) line) 
           (replace-regexp (regexp-quote check-in) check-out nil start end))
          ((string-match (regexp-quote check-out) line)
           (replace-regexp (regexp-quote check-out) check-in nil start end)))))

1. [✔] Something
2. [✔] Done
3. [ ] To be done

(defun rcd-highlight-list (list)
  "Uses LIST to highlight strings in buffer."
  (hi-lock-mode)
  (let* ((list (delete "" list))
        (highlights hi-lock-face-defaults))
    (while list
      (highlight-regexp (regexp-quote (pop list)) (pop highlights)))))

(rcd-highlight-list '("[ ]" "[✔]"))

-- 
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]