Giter Site home page Giter Site logo

Comments (7)

jrblevin avatar jrblevin commented on May 18, 2024

Thanks--I will try to work this in soon. Would, say, <M-mouse-1> (hold meta and click first mouse button) be an appropriate keybinding for this?

Edit: I realize now that <M-mouse-1> would interfere with secondary selection (which I don't use). So, I'm open to other suggestions on the binding.

from markdown-mode.

hmelman avatar hmelman commented on May 18, 2024

On Jul 28, 2015, at 4:02 PM, Jason Blevins [email protected] wrote:

Thanks--I will try to work this in soon. Would, say, (hold meta and click first mouse button) be an appropriate keybinding for this?

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

from markdown-mode.

jrblevin avatar jrblevin commented on May 18, 2024

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 make-button I'd be happy to take a look.

from markdown-mode.

hmelman avatar hmelman commented on May 18, 2024

On Aug 7, 2015, at 3:37 PM, Jason Blevins [email protected] wrote:

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 make-button I'd be happy to take a look.

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

from markdown-mode.

hmelman avatar hmelman commented on May 18, 2024

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
--- /Users/hmelman/elisp/markdown-mode.el Sun Aug 9 16:14:54 2015


*** 572,577 ****
--- 572,582 ----
;; this variable buffer-local allows `markdown-mode' to override
;; the default behavior induced when the global variable is non-nil.
;;

  • ;; * `markdown-make-gfm-checkboxes-buttons' - Whether GitHub Flavored
  • ;; Markdown style checkboxes should be turned into buttons that can
  • ;; be toggled with mouse-1 or RET. If non-nil buttons are enabled, the
  • ;; default is t. This works in markdown-mode' as well asgfm-mode'.
  • ;;
    ;; Additionally, the faces used for syntax highlighting can be modified to
    ;; your liking by issuing M-x customize-group RET markdown-faces
    ;; or by using the "Markdown Faces" link at the bottom of the mode
    *** 733,738 ****
    --- 738,744 ----
    ;; * Matt McClure [email protected] for a patch to prevent
    ;; overwriting source files with .html extensions upon export.
    ;; * Roger Bolsius [email protected] for ordered list improvements.
  • ;; * Howard Melman [email protected] for supporting gfm checkboxes as buttons.
    ;; * Google's Open Source Programs Office for recognizing the project with
    ;; a monetary contribution in June 2015.

*** 966,971 ****
--- 972,982 ----
(const :tag "lazy lock" lazy-lock-mode)
(const :tag "jit lock" jit-lock-mode)))

  • (defcustom markdown-make-gfm-checkboxes-buttons t
  • "When non-nil, make GFM checkboxes into buttons."
  • :group 'markdown
  • :type 'boolean)

  • ;;; Font Lock =================================================================

*** 1055,1060 ****
--- 1066,1077 ----
(defvar markdown-metadata-value-face 'markdown-metadata-value-face
"Face name to use for metadata values.")

  • (defvar markdown-gfm-checkbox-face 'markdown-gfm-checkbox-face

  • "Face name to use for GFM checkboxes.")

  • (defvar markdown-highlight-face 'markdown-highlight-face

  • "Face name to use for mouse highlighting.")

  • (defgroup markdown-faces nil
    "Faces used in Markdown Mode"
    :group 'markdown


    *** 1200,1205 ****
    --- 1217,1232 ----
    "Face for metadata values."
    :group 'markdown-faces)

  • (defface markdown-gfm-checkbox-face

  • '((t (:inherit font-lock-keyword-face)))

  • "Face for GFM checkboxes."

  • :group 'markdown-faces)

  • (defface markdown-highlight-face

  • '((t (:inherit highlight)))

  • "Face for mouse highlighting."

  • :group 'markdown-faces)
    q+
    (defconst markdown-regex-link-inline
    "(!)?([([^]^][^]]|)])((([^)]?)(?:\s-+("[^\"]*"))?))"
    "Regular expression for a text or an image link text.


*** 1369,1374 ****
--- 1396,1406 ----
"|" markdown-regex-angle-uri ")")
"Regular expression for matching any recognized link.")

  • (defconst markdown-regex-gfm-checkbox

  • " ([[ xX]]) "

  • "Regular expression for matching GFM checkboxes.

  • Group 1 matches the text to become a button.")

  • (defconst markdown-regex-block-separator
    "(`|(\n[ \t]*\n)[^\n \t])"
    "Regular expression for matching block boundaries.")


    *** 4843,4848 ****
    --- 4875,4921 ----
    (markdown-reload-extensions)))

  • ;;; GFM Checkboxes as Buttons =================================================

  • (require 'button)

  • (define-button-type 'markdown-gfm-checkbox-button

  • 'follow-link t

  • 'face 'markdown-gfm-checkbox-face

  • 'mouse-face 'markdown-highlight-face

  • 'action #'markdown-toggle-gfm-checkbox)

  • (defun markdown-toggle-gfm-checkbox (button)

  • "Toggle a GFM checkbox clicked on."

  • (save-match-data

  • (save-excursion
    
  •   (goto-char (button-start button))
    
  •   (cond ((looking-at "\[ \]")
    
  •          (replace-match "[x]" nil t))
    
  •         ((looking-at "\[[xX]\]")
    
  •          (replace-match "[ ]" nil t))))))
    
  • (defun markdown-make-gfm-checkboxes-buttons (start end)

  • "Make GFM checkboxes buttons in region between START and END."

  • (save-excursion

  • (goto-char start)
    
  • (let ((case-fold-search t))
    
  •   (save-excursion
    
  • (while (re-search-forward markdown-regex-gfm-checkbox end t)

  • (make-button (match-beginning 1) (match-end 1) 
    
  •                    :type 'markdown-gfm-checkbox-button))))))
    
  • ;; Called when any modification is made to buffer text.

  • (defun markdown-gfm-checkbox-after-change-function (beg end old-len)

  • "Add to `after-change-functions' to setup GFM checkboxes as buttons."

  • (save-excursion

  • (save-match-data
    
  •   ;; Rescan between start of line from `beg' and start of line after`end'.
    
  •   (markdown-make-gfm-checkboxes-buttons
    
  •    (progn (goto-char beg) (beginning-of-line) (point))
    
  •    (progn (goto-char end) (forward-line 1) (point))))))
    

  • ;;; Mode Definition ==========================================================

    (defun markdown-show-version ()


    *** 4954,4959 ****
    --- 5027,5037 ----
    ;; Anytime text changes make sure it gets fontified correctly
    (add-hook 'after-change-functions 'markdown-check-change-for-wiki-link t t)

  • ;; Make checkboxes buttons

  • (when markdown-make-gfm-checkboxes-buttons

  • (markdown-make-gfm-checkboxes-buttons (point-min) (point-max))
    
  • (add-hook 'after-change-functions 'markdown-gfm-checkbox-after-change-function t t))
    
  • ;; If we left the buffer there is a really good chance we were
    ;; creating one of the wiki link documents. Make sure we get
    ;; refontified when we come back.

from markdown-mode.

jrblevin avatar jrblevin commented on May 18, 2024

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.

from markdown-mode.

hmelman avatar hmelman commented on May 18, 2024

On Aug 13, 2015, at 12:44 AM, Jason Blevins [email protected] wrote:

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.

Great!

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.

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

from markdown-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.