Skip to content

Commit

Permalink
Merge pull request #1169 from Sasanidas/add-markdown-insert-link
Browse files Browse the repository at this point in the history
Add `markdown-mode` command `markdown-insert-link`
  • Loading branch information
cxxxr authored Nov 29, 2023
2 parents 02fda3f + bc94b74 commit 9dbce7a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions extensions/markdown-mode/markdown-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,37 @@
(variable-value 'tab-width) 4
(variable-value 'calc-indent-function) 'markdown-calc-indent))

(define-key *markdown-mode-keymap* "C-c C-l" 'markdown-insert-link)

(defun markdown-calc-indent (point)
(with-point ((point point))
(let ((tab-width (variable-value 'tab-width :default point))
(column (point-column point)))
(+ column (- tab-width (rem column tab-width))))))

(define-command markdown-insert-link () ()
(let ((url (prompt-for-string "URL: "
:history-symbol 'mh-markdown-url))
(text
(prompt-for-string "Link text (blank for plain URL): "))
(title
(prompt-for-string "Title (tooltip text, optional): ")))
(with-point ((p (current-point)))
(cond
((and url
(uiop:emptyp text)
(uiop:emptyp title))
(insert-string p (format nil "<~a>" url)))
((and url text (uiop:emptyp title))
(insert-string p (format nil
"[~a](~a)"
text
url)))
((and url text title)
(insert-string p (format nil
"[~a](~a \"~a\")"
text
url
title)))))))

(define-file-type ("md" "markdown") markdown-mode)

0 comments on commit 9dbce7a

Please sign in to comment.