-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function to toggle gfm checkbox #7
Comments
Thanks--I will try to work this in soon. Would, say, Edit: I realize now that |
Great. M-mouse-1 would work. I’ve been using M-mouse-2. All the M-mouse keys default to secondary-selection functions that I think no one uses, so I think it’s fine to use any of them. As I said, an implementation using make-button might be nice. You’d get a mouse-over face for free. It would involve scanning the buffer at startup and an after-change hook but it’s not too hard. If you’d like some code for that I could take a shot. Howard |
Thanks again, Howard. Sorry for the delay in responding. GFM features are lower priority for me than some other things right now, like fixing known bugs and improving the core Markdown functionality, but if you want to take a shot at a patch for implementing this with |
On Aug 7, 2015, at 3:37 PM, Jason Blevins notifications@github.com wrote:
Thanks again, and I agree with your prioritization. Ok, I have something working. Like other buttons It toggles with both mouse-1 and RET when in a checkbox and is enabled on a defcustom for markdown-make-gfm-checkboxes-buttons. Currently it’s tied into gfm-mode. If you approve I’d rather it be in the standard markdown-mode. I’d still keep the markdown-make-gfm-checkboxes-buttons option, but I’d change some names to make it fit in better. Marked 2 has a preference to render checkboxes that’s separate from other GFM options. As a result I use these in many small notes that are lists of things (movies to see, restaurants to try, etc.) where I don’t care about the other GFM features. Let me know what you’d prefer. Howard |
Here’s a patch that applies it to markdown-mode. Let me know what you think. *** /Users/hmelman/.emacs.d/elpa/markdown-mode-20150807.424/markdown-mode.el Sat Aug 8 14:43:25 2015 *** 572,577 ****
*** 966,971 ****
*** 1055,1060 ****
*** 1369,1374 ****
|
Thanks for this patch. I just got around to applying and testing it and it looks fine to me. I did make one small change: I used the same face for checkboxes as was used for list markers. Also, I think it's fine to enable this in markdown-mode. Here is the commit: 4121324. One more thing: if you could write a test case or two to add to tests/markdown-test.el, that would be very helpful. I will close this issue now, so please just start a new pull request if you want to add some tests. |
On Aug 13, 2015, at 12:44 AM, Jason Blevins notifications@github.com wrote:
Great!
Ok. I haven’t written tests for emacs before so this will be a learning experience. I’m busy for the next week but hope to get to it after that. Howard |
I find the following function useful to toggle gfm style checkboxes with the mouse. Perhaps it's useful to include in markdown-mode. Maybe it would be better implemented using make-button.
(defun hrm-markdown-toggle-gfm-check-box (event)
"Click in a gfm task list and toggle its state."
(interactive "*e")
;; go to where the event occurred
(set-buffer (window-buffer (posn-window (event-start event))))
(goto-char (posn-point (event-start event)))
;; assume on a list line (so false positive if [ ] in middle of text)
;; point could be at either position inside the checkbox
;; " [| ] " or " [ |] " or " [|X] " or " [X|] "
(save-match-data
(save-excursion
(forward-char -2)
(let* ((box-regexp " [([ xX])] ")
(at-box (looking-at box-regexp)))
(unless at-box
(forward-char -1)
(setq at-box (looking-at box-regexp)))
(if at-box
(replace-match (if (string= " " (match-string 1)) "x" " ")
nil nil nil 1))))))
The text was updated successfully, but these errors were encountered: