From 31884d136fe18e402f8d1c83d68c005671a767c5 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 10 Feb 2021 09:13:07 +0100 Subject: Update markdown-mode and yaml-mode --- .emacs.d/lisp/markdown-mode.el | 167 +++++++++++++++++++++++++++++++++-------- .emacs.d/lisp/yaml-mode.el | 8 +- 2 files changed, 141 insertions(+), 34 deletions(-) (limited to '.emacs.d/lisp') diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 542de4e..9522da4 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -48,6 +48,8 @@ (defvar flyspell-generic-check-word-predicate) (defvar electric-pair-pairs) +(declare-function project-roots "project") + ;;; Constants ================================================================= @@ -243,6 +245,22 @@ This is the default search behavior of Ikiwiki." :safe 'booleanp :package-version '(markdown-mode . "2.2")) +(defcustom markdown-wiki-link-search-type nil + "Searching type for markdown wiki link. + +sub-directories: search for wiki link targets in sub directories +parent-directories: search for wiki link targets in parent directories +project: search for wiki link targets under project root" + :group 'markdown + :type '(set + (const :tag "search wiki link from subdirectories" sub-directories) + (const :tag "search wiki link from parent directories" parent-directories) + (const :tag "search wiki link under project root" project)) + :package-version '(markdown-mode . "2.5")) + +(make-obsolete-variable 'markdown-wiki-link-search-subdirectories 'markdown-wiki-link-search-type "2.5") +(make-obsolete-variable 'markdown-wiki-link-search-parent-directories 'markdown-wiki-link-search-type "2.5") + (defcustom markdown-wiki-link-fontify-missing nil "When non-nil, change wiki link face according to existence of target files. This is expensive because it requires checking for the file each time the buffer @@ -427,6 +445,13 @@ The car is used for subscript, the cdr is used for superscripts." :group 'markdown :type 'string) +(defcustom markdown-ordered-list-enumeration t + "When non-nil, use enumerated numbers(1. 2. 3. etc.) for ordered list marker. +While nil, always uses '1.' for the marker" + :group 'markdown + :type 'boolean + :package-version '(markdown-mode . "2.5")) + (defcustom markdown-nested-imenu-heading-index t "Use nested or flat imenu heading index. A nested index may provide more natural browsing from the menu, @@ -4410,6 +4435,49 @@ at the beginning of the block." do (progn (when lang (markdown-gfm-add-used-language lang)) (goto-char (next-single-property-change (point) prop))))))) +(defun markdown-insert-foldable-block () + "Insert details disclosure element to make content foldable. +If a region is active, wrap this region with the disclosure +element. More detais here 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details'." + (interactive) + (let ((details-open-tag "
") + (details-close-tag "
") + (summary-open-tag "") + (summary-close-tag " ")) + (if (use-region-p) + (let* ((b (region-beginning)) + (e (region-end)) + (indent (progn (goto-char b) (current-indentation)))) + (goto-char e) + ;; if we're on a blank line, don't newline, otherwise the tags + ;; should go on its own line + (unless (looking-back "\n" nil) + (newline)) + (indent-to indent) + (insert details-close-tag) + (markdown-ensure-blank-line-after) + (goto-char b) + ;; if we're on a blank line, insert the quotes here, otherwise + ;; add a new line first + (unless (looking-at-p "\n") + (newline) + (forward-line -1)) + (markdown-ensure-blank-line-before) + (indent-to indent) + (insert details-open-tag "\n") + (insert summary-open-tag summary-close-tag) + (search-backward summary-close-tag)) + (let ((indent (current-indentation))) + (delete-horizontal-space :backward-only) + (markdown-ensure-blank-line-before) + (indent-to indent) + (insert details-open-tag "\n") + (insert summary-open-tag summary-close-tag "\n") + (insert details-close-tag) + (indent-to indent) + (markdown-ensure-blank-line-after) + (search-backward summary-close-tag))))) + ;;; Footnotes ================================================================= @@ -5155,6 +5223,7 @@ Assumes match data is available for `markdown-regex-italic'." (propertize "C = GFM code" 'face 'markdown-code-face) ", " (propertize "pre" 'face 'markdown-pre-face) ", " (propertize "footnote" 'face 'markdown-footnote-text-face) ", " + (propertize "F = foldable" 'face 'markdown-bold-face) ", " (propertize "q = blockquote" 'face 'markdown-blockquote-face) ", " (propertize "h & 1-6 = heading" 'face 'markdown-header-face) ", " (propertize "- = hr" 'face 'markdown-hr-face) ", " @@ -5188,6 +5257,7 @@ Assumes match data is available for `markdown-regex-italic'." (define-key map (kbd "c") 'markdown-insert-code) (define-key map (kbd "C") 'markdown-insert-gfm-code-block) (define-key map (kbd "f") 'markdown-insert-footnote) + (define-key map (kbd "F") 'markdown-insert-foldable-block) (define-key map (kbd "h") 'markdown-insert-header-dwim) (define-key map (kbd "H") 'markdown-insert-header-setext-dwim) (define-key map (kbd "i") 'markdown-insert-italic) @@ -5499,6 +5569,7 @@ See also `markdown-mode-map'.") ["GFM Code Block" markdown-insert-gfm-code-block] ["Edit Code Block" markdown-edit-code-block :enable (markdown-code-block-at-point-p)] + ["Foldable Block" markdown-insert-foldable-block] "---" ["Blockquote Region" markdown-blockquote-region] ["Preformatted Region" markdown-pre-region] @@ -6048,7 +6119,7 @@ increase the indentation by one level." (>= (forward-line -1) 0)))) (let* ((old-prefix (match-string 1)) (old-spacing (match-string 2)) - (new-prefix (if old-prefix + (new-prefix (if (and old-prefix markdown-ordered-list-enumeration) (int-to-string (1+ (string-to-number old-prefix))) "1")) (space-adjust (- (length old-prefix) (length new-prefix))) @@ -6173,7 +6244,10 @@ a list." (= (length cur-item) (length prev-item))) (save-excursion (replace-match - (concat pfx (number-to-string (setq idx (1+ idx))) ". "))) + (if (not markdown-ordered-list-enumeration) + (concat pfx "1. ") + (cl-incf idx) + (concat pfx (number-to-string idx) ". ")))) (setq sep nil)) ;; indented a level ((< (length pfx) (length cpfx)) @@ -7820,6 +7894,29 @@ The location of the alias component depends on the value of (match-string-no-properties 3) (or (match-string-no-properties 5) (match-string-no-properties 3)))) +(defun markdown--wiki-link-search-types () + (let ((ret (and markdown-wiki-link-search-type + (cl-copy-list markdown-wiki-link-search-type)))) + (when (and markdown-wiki-link-search-subdirectories + (not (memq 'sub-directories markdown-wiki-link-search-type))) + (push 'sub-directories ret)) + (when (and markdown-wiki-link-search-parent-directories + (not (memq 'parent-directories markdown-wiki-link-search-type))) + (push 'parent-directories ret)) + ret)) + +(defun markdown--project-root () + (or (cl-loop for dir in '(".git" ".hg" ".svn") + when (locate-dominating-file default-directory dir) + return it) + (progn + (require 'project) + (let ((project (project-current t))) + (with-no-warnings + (if (fboundp 'project-root) + (project-root project) + (car (project-roots project)))))))) + (defun markdown-convert-wiki-link-to-filename (name) "Generate a filename from the wiki link NAME. Spaces in NAME are replaced with `markdown-link-space-sub-char'. @@ -7829,35 +7926,43 @@ directory first, then in subdirectories if `markdown-wiki-link-search-subdirectories' is non-nil, and then in parent directories if `markdown-wiki-link-search-parent-directories' is non-nil." - (let* ((basename (replace-regexp-in-string - "[[:space:]\n]" markdown-link-space-sub-char name)) - (basename (if (derived-mode-p 'gfm-mode) - (concat (upcase (substring basename 0 1)) - (downcase (substring basename 1 nil))) - basename)) - directory extension default candidates dir) - (when buffer-file-name - (setq directory (file-name-directory buffer-file-name) - extension (file-name-extension buffer-file-name))) - (setq default (concat basename - (when extension (concat "." extension)))) - (cond - ;; Look in current directory first. - ((or (null buffer-file-name) - (file-exists-p default)) - default) - ;; Possibly search in subdirectories, next. - ((and markdown-wiki-link-search-subdirectories - (setq candidates - (directory-files-recursively - directory (concat "^" default "$")))) - (car candidates)) - ;; Possibly search in parent directories as a last resort. - ((and markdown-wiki-link-search-parent-directories - (setq dir (locate-dominating-file directory default))) - (concat dir default)) - ;; If nothing is found, return default in current directory. - (t default)))) + (save-match-data + ;; This function must not overwrite match data(PR #590) + (let* ((basename (replace-regexp-in-string + "[[:space:]\n]" markdown-link-space-sub-char name)) + (basename (if (derived-mode-p 'gfm-mode) + (concat (upcase (substring basename 0 1)) + (downcase (substring basename 1 nil))) + basename)) + (search-types (markdown--wiki-link-search-types)) + directory extension default candidates dir) + (when buffer-file-name + (setq directory (file-name-directory buffer-file-name) + extension (file-name-extension buffer-file-name))) + (setq default (concat basename + (when extension (concat "." extension)))) + (cond + ;; Look in current directory first. + ((or (null buffer-file-name) + (file-exists-p default)) + default) + ;; Possibly search in subdirectories, next. + ((and (memq 'sub-directories search-types) + (setq candidates + (directory-files-recursively + directory (concat "^" default "$")))) + (car candidates)) + ;; Possibly search in parent directories as a last resort. + ((and (memq 'parent-directories search-types) + (setq dir (locate-dominating-file directory default))) + (concat dir default)) + ((and (memq 'project search-types) + (setq candidates + (directory-files-recursively + (markdown--project-root) (concat "^" default "$")))) + (car candidates)) + ;; If nothing is found, return default in current directory. + (t default))))) (defun markdown-follow-wiki-link (name &optional other) "Follow the wiki link NAME. diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index 4914218..50d790b 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el @@ -7,7 +7,7 @@ ;; Maintainer: Vasilij Schneidermann ;; Package-Requires: ((emacs "24.1")) ;; Keywords: data yaml -;; Version: 0.0.14 +;; Version: 0.0.15 ;; This file is not part of Emacs @@ -117,7 +117,7 @@ that key is pressed to begin a block literal." ;; Constants -(defconst yaml-mode-version "0.0.14" "Version of `yaml-mode'.") +(defconst yaml-mode-version "0.0.15" "Version of `yaml-mode'.") (defconst yaml-blank-line-re "^ *$" "Regexp matching a line containing only (valid) whitespace.") @@ -151,7 +151,7 @@ that key is pressed to begin a block literal." "Regexp indicating the beginning of a scalar context.") (defconst yaml-nested-map-re - (concat "[^#]*: *\\(?:&.*\\|{ *\\|" yaml-tag-re " *\\)?$") + (concat "[^#\n]*: *\\(?:&.*\\|{ *\\|" yaml-tag-re " *\\)?$") "Regexp matching a line beginning a YAML nested structure.") (defconst yaml-block-literal-base-re " *[>|][-+0-9]* *\\(?:\n\\|\\'\\)" @@ -322,6 +322,8 @@ artificially limited to the value of (unless (looking-at yaml-blank-line-re) (setq min-level (min min-level (current-indentation)))) (forward-line -1)) + (when (looking-at-p " *- ") + (setq min-level (- min-level 2))) (cond ((and (< (current-indentation) min-level) (looking-at yaml-block-literal-re)) -- cgit v1.3