summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2022-11-24 23:02:18 +0000
committerMatthew Lemon <matt@matthewlemon.com>2022-11-24 23:02:18 +0000
commit0604940031aadff4e35f0b00bfd459a27e69cb1a (patch)
tree8be99c0dc955941ac04d01d4f4c1a9cf7fed56db
parentdcdb1ff2aec04056d861c7342826a2183bd7ca6e (diff)
added function to clear checks from region
In markdown list.
-rw-r--r--init.el37
1 files changed, 36 insertions, 1 deletions
diff --git a/init.el b/init.el
index 1d7d33a..c70f798 100644
--- a/init.el
+++ b/init.el
@@ -225,6 +225,40 @@ Restart works only on graphic display."
(setq coding-system-for-write 'utf-8)
;; for markdown mode
+(defun mrl/get-start-and-lines-in-region ()
+ "Cumbersome newbie way to get start line and number
+of lines in region."
+ (let (pos1 pos2)
+ (setq pos1 (region-beginning)
+ pos2 (region-end))
+ (let ((line1 (line-number-at-pos pos1))
+ (line2 (line-number-at-pos pos2)))
+ (list line1 (- line2 line1)))))
+
+(defun mrl/clear-check-region (start lines)
+ "Clears check marks given a start line and number
+of lines to run through."
+ (setq count 0)
+ (while (> lines 0)
+ (save-excursion
+ (goto-line (+ start count))
+ (beginning-of-line)
+ (forward-char 3)
+ (delete-char 1)
+ (insert-char ?\s))
+ (next-line)
+ (setq count (+ count 1))
+ (setq lines (- lines 1))))
+
+
+(defun mrl/clear-check-from-region ()
+ "Interactive func to clear markdown checks from a region."
+ (interactive)
+ (save-excursion
+ (mrl/clear-check-region
+ (car (mrl/get-start-and-lines-in-region))
+ (car (last (mrl/get-start-and-lines-in-region))))))
+
;; do this for a region next
(defun mrl/clear-check-single-line (&optional lines)
"Remove the check from LINES number of markdown checkbox lines."
@@ -243,7 +277,8 @@ Restart works only on graphic display."
(use-package markdown-mode
:ensure t
:bind (:map markdown-mode-map
- ("C-c C-v" . mrl/clear-check-single-line))
+ ("C-c C-q" . mrl/clear-check-single-line)
+ ("C-c C-v" . mrl/clear-check-from-region))
:hook (markdown-mode-hook . (lambda ()
(when buffer-file-name
(add-hook 'after-save-hook