summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2021-02-10 09:13:07 +0100
committerSimeon Simeonov2021-02-10 09:13:07 +0100
commit31884d136fe18e402f8d1c83d68c005671a767c5 (patch)
tree83826812c3031f80bbb51734d4e0509aa55d70b3
parent97d084eb0846f3c2edbb199fed7226370471cd5a (diff)
Update markdown-mode and yaml-mode
-rw-r--r--.emacs.d/lisp/markdown-mode.el167
-rw-r--r--.emacs.d/lisp/yaml-mode.el8
2 files changed, 141 insertions, 34 deletions
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 @@
48(defvar flyspell-generic-check-word-predicate) 48(defvar flyspell-generic-check-word-predicate)
49(defvar electric-pair-pairs) 49(defvar electric-pair-pairs)
50 50
51(declare-function project-roots "project")
52
51 53
52;;; Constants ================================================================= 54;;; Constants =================================================================
53 55
@@ -243,6 +245,22 @@ This is the default search behavior of Ikiwiki."
243 :safe 'booleanp 245 :safe 'booleanp
244 :package-version '(markdown-mode . "2.2")) 246 :package-version '(markdown-mode . "2.2"))
245 247
248(defcustom markdown-wiki-link-search-type nil
249 "Searching type for markdown wiki link.
250
251sub-directories: search for wiki link targets in sub directories
252parent-directories: search for wiki link targets in parent directories
253project: search for wiki link targets under project root"
254 :group 'markdown
255 :type '(set
256 (const :tag "search wiki link from subdirectories" sub-directories)
257 (const :tag "search wiki link from parent directories" parent-directories)
258 (const :tag "search wiki link under project root" project))
259 :package-version '(markdown-mode . "2.5"))
260
261(make-obsolete-variable 'markdown-wiki-link-search-subdirectories 'markdown-wiki-link-search-type "2.5")
262(make-obsolete-variable 'markdown-wiki-link-search-parent-directories 'markdown-wiki-link-search-type "2.5")
263
246(defcustom markdown-wiki-link-fontify-missing nil 264(defcustom markdown-wiki-link-fontify-missing nil
247 "When non-nil, change wiki link face according to existence of target files. 265 "When non-nil, change wiki link face according to existence of target files.
248This is expensive because it requires checking for the file each time the buffer 266This 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."
427 :group 'markdown 445 :group 'markdown
428 :type 'string) 446 :type 'string)
429 447
448(defcustom markdown-ordered-list-enumeration t
449 "When non-nil, use enumerated numbers(1. 2. 3. etc.) for ordered list marker.
450While nil, always uses '1.' for the marker"
451 :group 'markdown
452 :type 'boolean
453 :package-version '(markdown-mode . "2.5"))
454
430(defcustom markdown-nested-imenu-heading-index t 455(defcustom markdown-nested-imenu-heading-index t
431 "Use nested or flat imenu heading index. 456 "Use nested or flat imenu heading index.
432A nested index may provide more natural browsing from the menu, 457A nested index may provide more natural browsing from the menu,
@@ -4410,6 +4435,49 @@ at the beginning of the block."
4410 do (progn (when lang (markdown-gfm-add-used-language lang)) 4435 do (progn (when lang (markdown-gfm-add-used-language lang))
4411 (goto-char (next-single-property-change (point) prop))))))) 4436 (goto-char (next-single-property-change (point) prop)))))))
4412 4437
4438(defun markdown-insert-foldable-block ()
4439 "Insert details disclosure element to make content foldable.
4440If a region is active, wrap this region with the disclosure
4441element. More detais here 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details'."
4442 (interactive)
4443 (let ((details-open-tag "<details>")
4444 (details-close-tag "</details>")
4445 (summary-open-tag "<summary>")
4446 (summary-close-tag " </summary>"))
4447 (if (use-region-p)
4448 (let* ((b (region-beginning))
4449 (e (region-end))
4450 (indent (progn (goto-char b) (current-indentation))))
4451 (goto-char e)
4452 ;; if we're on a blank line, don't newline, otherwise the tags
4453 ;; should go on its own line
4454 (unless (looking-back "\n" nil)
4455 (newline))
4456 (indent-to indent)
4457 (insert details-close-tag)
4458 (markdown-ensure-blank-line-after)
4459 (goto-char b)
4460 ;; if we're on a blank line, insert the quotes here, otherwise
4461 ;; add a new line first
4462 (unless (looking-at-p "\n")
4463 (newline)
4464 (forward-line -1))
4465 (markdown-ensure-blank-line-before)
4466 (indent-to indent)
4467 (insert details-open-tag "\n")
4468 (insert summary-open-tag summary-close-tag)
4469 (search-backward summary-close-tag))
4470 (let ((indent (current-indentation)))
4471 (delete-horizontal-space :backward-only)
4472 (markdown-ensure-blank-line-before)
4473 (indent-to indent)
4474 (insert details-open-tag "\n")
4475 (insert summary-open-tag summary-close-tag "\n")
4476 (insert details-close-tag)
4477 (indent-to indent)
4478 (markdown-ensure-blank-line-after)
4479 (search-backward summary-close-tag)))))
4480
4413 4481
4414;;; Footnotes ================================================================= 4482;;; Footnotes =================================================================
4415 4483
@@ -5155,6 +5223,7 @@ Assumes match data is available for `markdown-regex-italic'."
5155 (propertize "C = GFM code" 'face 'markdown-code-face) ", " 5223 (propertize "C = GFM code" 'face 'markdown-code-face) ", "
5156 (propertize "pre" 'face 'markdown-pre-face) ", " 5224 (propertize "pre" 'face 'markdown-pre-face) ", "
5157 (propertize "footnote" 'face 'markdown-footnote-text-face) ", " 5225 (propertize "footnote" 'face 'markdown-footnote-text-face) ", "
5226 (propertize "F = foldable" 'face 'markdown-bold-face) ", "
5158 (propertize "q = blockquote" 'face 'markdown-blockquote-face) ", " 5227 (propertize "q = blockquote" 'face 'markdown-blockquote-face) ", "
5159 (propertize "h & 1-6 = heading" 'face 'markdown-header-face) ", " 5228 (propertize "h & 1-6 = heading" 'face 'markdown-header-face) ", "
5160 (propertize "- = hr" 'face 'markdown-hr-face) ", " 5229 (propertize "- = hr" 'face 'markdown-hr-face) ", "
@@ -5188,6 +5257,7 @@ Assumes match data is available for `markdown-regex-italic'."
5188 (define-key map (kbd "c") 'markdown-insert-code) 5257 (define-key map (kbd "c") 'markdown-insert-code)
5189 (define-key map (kbd "C") 'markdown-insert-gfm-code-block) 5258 (define-key map (kbd "C") 'markdown-insert-gfm-code-block)
5190 (define-key map (kbd "f") 'markdown-insert-footnote) 5259 (define-key map (kbd "f") 'markdown-insert-footnote)
5260 (define-key map (kbd "F") 'markdown-insert-foldable-block)
5191 (define-key map (kbd "h") 'markdown-insert-header-dwim) 5261 (define-key map (kbd "h") 'markdown-insert-header-dwim)
5192 (define-key map (kbd "H") 'markdown-insert-header-setext-dwim) 5262 (define-key map (kbd "H") 'markdown-insert-header-setext-dwim)
5193 (define-key map (kbd "i") 'markdown-insert-italic) 5263 (define-key map (kbd "i") 'markdown-insert-italic)
@@ -5499,6 +5569,7 @@ See also `markdown-mode-map'.")
5499 ["GFM Code Block" markdown-insert-gfm-code-block] 5569 ["GFM Code Block" markdown-insert-gfm-code-block]
5500 ["Edit Code Block" markdown-edit-code-block 5570 ["Edit Code Block" markdown-edit-code-block
5501 :enable (markdown-code-block-at-point-p)] 5571 :enable (markdown-code-block-at-point-p)]
5572 ["Foldable Block" markdown-insert-foldable-block]
5502 "---" 5573 "---"
5503 ["Blockquote Region" markdown-blockquote-region] 5574 ["Blockquote Region" markdown-blockquote-region]
5504 ["Preformatted Region" markdown-pre-region] 5575 ["Preformatted Region" markdown-pre-region]
@@ -6048,7 +6119,7 @@ increase the indentation by one level."
6048 (>= (forward-line -1) 0)))) 6119 (>= (forward-line -1) 0))))
6049 (let* ((old-prefix (match-string 1)) 6120 (let* ((old-prefix (match-string 1))
6050 (old-spacing (match-string 2)) 6121 (old-spacing (match-string 2))
6051 (new-prefix (if old-prefix 6122 (new-prefix (if (and old-prefix markdown-ordered-list-enumeration)
6052 (int-to-string (1+ (string-to-number old-prefix))) 6123 (int-to-string (1+ (string-to-number old-prefix)))
6053 "1")) 6124 "1"))
6054 (space-adjust (- (length old-prefix) (length new-prefix))) 6125 (space-adjust (- (length old-prefix) (length new-prefix)))
@@ -6173,7 +6244,10 @@ a list."
6173 (= (length cur-item) (length prev-item))) 6244 (= (length cur-item) (length prev-item)))
6174 (save-excursion 6245 (save-excursion
6175 (replace-match 6246 (replace-match
6176 (concat pfx (number-to-string (setq idx (1+ idx))) ". "))) 6247 (if (not markdown-ordered-list-enumeration)
6248 (concat pfx "1. ")
6249 (cl-incf idx)
6250 (concat pfx (number-to-string idx) ". "))))
6177 (setq sep nil)) 6251 (setq sep nil))
6178 ;; indented a level 6252 ;; indented a level
6179 ((< (length pfx) (length cpfx)) 6253 ((< (length pfx) (length cpfx))
@@ -7820,6 +7894,29 @@ The location of the alias component depends on the value of
7820 (match-string-no-properties 3) 7894 (match-string-no-properties 3)
7821 (or (match-string-no-properties 5) (match-string-no-properties 3)))) 7895 (or (match-string-no-properties 5) (match-string-no-properties 3))))
7822 7896
7897(defun markdown--wiki-link-search-types ()
7898 (let ((ret (and markdown-wiki-link-search-type
7899 (cl-copy-list markdown-wiki-link-search-type))))
7900 (when (and markdown-wiki-link-search-subdirectories
7901 (not (memq 'sub-directories markdown-wiki-link-search-type)))
7902 (push 'sub-directories ret))
7903 (when (and markdown-wiki-link-search-parent-directories
7904 (not (memq 'parent-directories markdown-wiki-link-search-type)))
7905 (push 'parent-directories ret))
7906 ret))
7907
7908(defun markdown--project-root ()
7909 (or (cl-loop for dir in '(".git" ".hg" ".svn")
7910 when (locate-dominating-file default-directory dir)
7911 return it)
7912 (progn
7913 (require 'project)
7914 (let ((project (project-current t)))
7915 (with-no-warnings
7916 (if (fboundp 'project-root)
7917 (project-root project)
7918 (car (project-roots project))))))))
7919
7823(defun markdown-convert-wiki-link-to-filename (name) 7920(defun markdown-convert-wiki-link-to-filename (name)
7824 "Generate a filename from the wiki link NAME. 7921 "Generate a filename from the wiki link NAME.
7825Spaces in NAME are replaced with `markdown-link-space-sub-char'. 7922Spaces in NAME are replaced with `markdown-link-space-sub-char'.
@@ -7829,35 +7926,43 @@ directory first, then in subdirectories if
7829`markdown-wiki-link-search-subdirectories' is non-nil, and then 7926`markdown-wiki-link-search-subdirectories' is non-nil, and then
7830in parent directories if 7927in parent directories if
7831`markdown-wiki-link-search-parent-directories' is non-nil." 7928`markdown-wiki-link-search-parent-directories' is non-nil."
7832 (let* ((basename (replace-regexp-in-string 7929 (save-match-data
7833 "[[:space:]\n]" markdown-link-space-sub-char name)) 7930 ;; This function must not overwrite match data(PR #590)
7834 (basename (if (derived-mode-p 'gfm-mode) 7931 (let* ((basename (replace-regexp-in-string
7835 (concat (upcase (substring basename 0 1)) 7932 "[[:space:]\n]" markdown-link-space-sub-char name))
7836 (downcase (substring basename 1 nil))) 7933 (basename (if (derived-mode-p 'gfm-mode)
7837 basename)) 7934 (concat (upcase (substring basename 0 1))
7838 directory extension default candidates dir) 7935 (downcase (substring basename 1 nil)))
7839 (when buffer-file-name 7936 basename))
7840 (setq directory (file-name-directory buffer-file-name) 7937 (search-types (markdown--wiki-link-search-types))
7841 extension (file-name-extension buffer-file-name))) 7938 directory extension default candidates dir)
7842 (setq default (concat basename 7939 (when buffer-file-name
7843 (when extension (concat "." extension)))) 7940 (setq directory (file-name-directory buffer-file-name)
7844 (cond 7941 extension (file-name-extension buffer-file-name)))
7845 ;; Look in current directory first. 7942 (setq default (concat basename
7846 ((or (null buffer-file-name) 7943 (when extension (concat "." extension))))
7847 (file-exists-p default)) 7944 (cond
7848 default) 7945 ;; Look in current directory first.
7849 ;; Possibly search in subdirectories, next. 7946 ((or (null buffer-file-name)
7850 ((and markdown-wiki-link-search-subdirectories 7947 (file-exists-p default))
7851 (setq candidates 7948 default)
7852 (directory-files-recursively 7949 ;; Possibly search in subdirectories, next.
7853 directory (concat "^" default "$")))) 7950 ((and (memq 'sub-directories search-types)
7854 (car candidates)) 7951 (setq candidates
7855 ;; Possibly search in parent directories as a last resort. 7952 (directory-files-recursively
7856 ((and markdown-wiki-link-search-parent-directories 7953 directory (concat "^" default "$"))))
7857 (setq dir (locate-dominating-file directory default))) 7954 (car candidates))
7858 (concat dir default)) 7955 ;; Possibly search in parent directories as a last resort.
7859 ;; If nothing is found, return default in current directory. 7956 ((and (memq 'parent-directories search-types)
7860 (t default)))) 7957 (setq dir (locate-dominating-file directory default)))
7958 (concat dir default))
7959 ((and (memq 'project search-types)
7960 (setq candidates
7961 (directory-files-recursively
7962 (markdown--project-root) (concat "^" default "$"))))
7963 (car candidates))
7964 ;; If nothing is found, return default in current directory.
7965 (t default)))))
7861 7966
7862(defun markdown-follow-wiki-link (name &optional other) 7967(defun markdown-follow-wiki-link (name &optional other)
7863 "Follow the wiki link NAME. 7968 "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 @@
7;; Maintainer: Vasilij Schneidermann <mail@vasilij.de> 7;; Maintainer: Vasilij Schneidermann <mail@vasilij.de>
8;; Package-Requires: ((emacs "24.1")) 8;; Package-Requires: ((emacs "24.1"))
9;; Keywords: data yaml 9;; Keywords: data yaml
10;; Version: 0.0.14 10;; Version: 0.0.15
11 11
12;; This file is not part of Emacs 12;; This file is not part of Emacs
13 13
@@ -117,7 +117,7 @@ that key is pressed to begin a block literal."
117 117
118;; Constants 118;; Constants
119 119
120(defconst yaml-mode-version "0.0.14" "Version of `yaml-mode'.") 120(defconst yaml-mode-version "0.0.15" "Version of `yaml-mode'.")
121 121
122(defconst yaml-blank-line-re "^ *$" 122(defconst yaml-blank-line-re "^ *$"
123 "Regexp matching a line containing only (valid) whitespace.") 123 "Regexp matching a line containing only (valid) whitespace.")
@@ -151,7 +151,7 @@ that key is pressed to begin a block literal."
151 "Regexp indicating the beginning of a scalar context.") 151 "Regexp indicating the beginning of a scalar context.")
152 152
153(defconst yaml-nested-map-re 153(defconst yaml-nested-map-re
154 (concat "[^#]*: *\\(?:&.*\\|{ *\\|" yaml-tag-re " *\\)?$") 154 (concat "[^#\n]*: *\\(?:&.*\\|{ *\\|" yaml-tag-re " *\\)?$")
155 "Regexp matching a line beginning a YAML nested structure.") 155 "Regexp matching a line beginning a YAML nested structure.")
156 156
157(defconst yaml-block-literal-base-re " *[>|][-+0-9]* *\\(?:\n\\|\\'\\)" 157(defconst yaml-block-literal-base-re " *[>|][-+0-9]* *\\(?:\n\\|\\'\\)"
@@ -322,6 +322,8 @@ artificially limited to the value of
322 (unless (looking-at yaml-blank-line-re) 322 (unless (looking-at yaml-blank-line-re)
323 (setq min-level (min min-level (current-indentation)))) 323 (setq min-level (min min-level (current-indentation))))
324 (forward-line -1)) 324 (forward-line -1))
325 (when (looking-at-p " *- ")
326 (setq min-level (- min-level 2)))
325 (cond 327 (cond
326 ((and (< (current-indentation) min-level) 328 ((and (< (current-indentation) min-level)
327 (looking-at yaml-block-literal-re)) 329 (looking-at yaml-block-literal-re))