branch: externals/tempel commit 006ec9c361e243365cc0c709bb1ef5b39516d42b Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Add support for markdown source blocks (See #48) --- README.org | 9 +++++---- tempel.el | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index c6cccf53b4..2594af0e1a 100644 --- a/README.org +++ b/README.org @@ -39,10 +39,11 @@ bindings are defined in the ~tempel-map~ keymap. You can customize them there. A soon as you move before (behind) the first (last) field, the fields are finalized. -Tempel can hook into the abbrev mechanism of Emacs by enabling the -~tempel-abbrev-mode~ in a buffer or by enabling the ~tempel-global-abbrev-mode~. -Then the Tempel templates will be available via ~expand-abbrev~ which is usually -bound to ~C-x '~. +Tempel recognizes Org and Markdown source blocks and enables the appropriate +templates according to the language mode of the source block. Tempel can hook +into the abbrev mechanism of Emacs by enabling the ~tempel-abbrev-mode~ in a +buffer or by enabling the ~tempel-global-abbrev-mode~. Then the Tempel templates +will be available via ~expand-abbrev~ which is usually bound to ~C-x '~. Note that this package is not a competitor to the mature and widely used YASnippet library, which comes with many readily available snippet collections. diff --git a/tempel.el b/tempel.el index 46ddf91fce..00e5a48892 100644 --- a/tempel.el +++ b/tempel.el @@ -89,7 +89,9 @@ must return a list of templates which apply to the buffer or context." If a file is modified, added or removed, reload the templates." :type 'boolean) -(defcustom tempel-local-mode-hook (list #'tempel-org-src-block-mode) +(defcustom tempel-local-mode-hook + (list #'tempel-org-src-block-mode + #'tempel-markdown-block-mode) "Hooks which return the local mode at point, e.g., in Org source blocks." :type 'hook) @@ -486,6 +488,18 @@ This is meant to be a source in `tempel-template-sources'." (org-src-get-lang-mode lang) #'fundamental-mode))) +(declare-function markdown-code-block-at-point-p "markdown-mode") +(declare-function markdown-code-block-lang "markdown-mode") +(declare-function markdown-get-lang-mode "markdown-mode") +(defun tempel-markdown-block-mode () + "Return Markdown source block language mode when inside a source block." + (when (and (derived-mode-p 'markdown-mode) (markdown-code-block-at-point-p)) + (save-excursion + (if-let* ((lang (markdown-code-block-lang)) + (mode (markdown-get-lang-mode lang))) + mode + #'fundamental-mode)))) + (defun tempel--templates () "Return templates for current mode." (let (result)