1
- ;;; markdown-mode.el --- Emacs Major mode for Markdown-formatted text files
1
+ ;;; markdown-mode.el --- Emacs Major mode for Markdown-formatted text files -*- lexical-binding: t; -*-
2
2
3
3
;; Copyright (C) 2007-2016 Jason R. Blevins <
[email protected] >
4
4
;; Copyright (C) 2007, 2009 Edward O'Connor <
[email protected] >
@@ -1441,10 +1441,10 @@ Function is called repeatedly until it returns nil. For details, see
1441
1441
(unless (and (eq new-start start) (eq new-end end))
1442
1442
(cons new-start new-end)))))
1443
1443
1444
- (defun markdown-font-lock-extend-region-function (start end old-len )
1444
+ (defun markdown-font-lock-extend-region-function (start end _ )
1445
1445
"Used in `jit-lock-after-change-extend-region-functions'. Delegates to
1446
1446
`markdown-syntax-propertize-extend-region'. START and END are the previous
1447
- region to refontify, and OLD-LEN is the length of the region ."
1447
+ region to refontify."
1448
1448
(let ((res (markdown-syntax-propertize-extend-region start end)))
1449
1449
(when res
1450
1450
(setq jit-lock-start (car res)
@@ -1455,7 +1455,7 @@ region to refontify, and OLD-LEN is the length of the region."
1455
1455
(save-excursion
1456
1456
(goto-char start)
1457
1457
(let ((levels (markdown-calculate-list-levels))
1458
- indent pre-regexp close-regexp open close stop )
1458
+ indent pre-regexp close-regexp open close)
1459
1459
(while (and (< (point) end) (not close))
1460
1460
;; Search for a region with sufficient indentation
1461
1461
(if (null levels)
@@ -1829,7 +1829,6 @@ start which was previously propertized."
1829
1829
(save-excursion
1830
1830
(goto-char start)
1831
1831
(cl-loop
1832
- with skip = nil
1833
1832
while (re-search-forward markdown-regex-multimarkdown-metadata end t)
1834
1833
do (when (get-text-property (match-beginning 0)
1835
1834
'markdown-yaml-metadata-section)
@@ -2592,14 +2591,14 @@ upon failure."
2592
2591
"Search forward from point for the next list item with indentation LEVEL.
2593
2592
Set point to the beginning of the item, and return point, or nil
2594
2593
upon failure."
2595
- (let (bounds indent prev next)
2594
+ (let (bounds indent next)
2596
2595
(setq next (point))
2597
2596
(forward-line)
2598
2597
(setq indent (markdown-cur-line-indent))
2599
2598
(while
2600
2599
(cond
2601
2600
;; Stop at end of the buffer.
2602
- ((eobp) (setq prev nil) )
2601
+ ((eobp) nil)
2603
2602
;; Continue if the current line is blank
2604
2603
((markdown-cur-line-blank-p) t)
2605
2604
;; List item
@@ -2734,8 +2733,8 @@ intact additional processing."
2734
2733
(let (refs)
2735
2734
(while (re-search-forward markdown-regex-reference-definition nil t)
2736
2735
(let ((target (match-string-no-properties 2)))
2737
- (add-to-list ' refs target t )))
2738
- refs)))
2736
+ (cl-pushnew target refs :test #'equal )))
2737
+ (reverse refs) )))
2739
2738
2740
2739
(defun markdown-code-at-point-p ()
2741
2740
"Return non-nil if the point is at an inline code fragment.
@@ -2788,7 +2787,7 @@ GFM quoted code blocks. Calls `markdown-code-block-at-pos'."
2788
2787
"Return t if PROP from BEGIN to END is equal to one of the given VALUES.
2789
2788
Also returns t if PROP is a list containing one of the VALUES.
2790
2789
Return nil otherwise."
2791
- (let (loc props val )
2790
+ (let (props)
2792
2791
(catch 'found
2793
2792
(dolist (loc (number-sequence begin end))
2794
2793
(when (setq props (get-char-property loc prop))
@@ -3018,11 +3017,9 @@ into a variable to allow for dynamic let-binding.")
3018
3017
(enclosing-header
3019
3018
(cl-find-if ; just take first if multiple
3020
3019
(lambda (match-bounds)
3021
- (cl-destructuring-bind (start-match end-match) match-bounds
3022
- (and
3023
- (< (point) (cl-first end-match))
3024
- (save-excursion
3025
- (re-search-forward regexp (cl-second end-match) t)))))
3020
+ (cl-destructuring-bind (begin end) (cl-second match-bounds)
3021
+ (and (< (point) begin)
3022
+ (save-excursion (re-search-forward regexp end t)))))
3026
3023
header-bounds))
3027
3024
(header-begin
3028
3025
(when enclosing-header (cl-second (cl-first enclosing-header))))
@@ -3607,7 +3604,7 @@ Also see `markdown-pre-indentation'."
3607
3604
(goto-char loc)
3608
3605
(let* ((list-level (length (markdown-calculate-list-levels)))
3609
3606
(indent ""))
3610
- (dotimes (count list-level indent)
3607
+ (dotimes (_ list-level indent)
3611
3608
(setq indent (concat indent " "))))))
3612
3609
3613
3610
(defun markdown-insert-blockquote ()
@@ -3663,7 +3660,7 @@ Also see `markdown-blockquote-indentation'."
3663
3660
(goto-char loc)
3664
3661
(let* ((list-level (length (markdown-calculate-list-levels)))
3665
3662
indent)
3666
- (dotimes (count (1+ list-level) indent)
3663
+ (dotimes (_ (1+ list-level) indent)
3667
3664
(setq indent (concat indent " "))))))
3668
3665
3669
3666
(defun markdown-insert-pre ()
@@ -4060,7 +4057,7 @@ addresses, bold, italics, reference definition (add URI to kill
4060
4057
ring), footnote markers and text (kill both marker and text, add
4061
4058
text to kill ring), and list items."
4062
4059
(interactive "*")
4063
- (let (val tmp )
4060
+ (let (val)
4064
4061
(cond
4065
4062
;; Inline code
4066
4063
((markdown-code-at-point-p)
@@ -4254,7 +4251,7 @@ See `markdown-indent-line' and `markdown-indent-line'."
4254
4251
(defun markdown-exdent-region (beg end)
4255
4252
"Call `markdown-indent-region' on region from BEG to END with prefix."
4256
4253
(interactive "*r")
4257
- (markdown-indent-region (region-beginning) (region- end) t))
4254
+ (markdown-indent-region beg end t))
4258
4255
4259
4256
4260
4257
;;; Markup Completion =========================================================
@@ -4398,7 +4395,8 @@ match."
4398
4395
(or match (setq match (looking-back prev-regexp nil)))))
4399
4396
(unless match
4400
4397
(save-excursion (funcall function))))))
4401
- (add-to-list 'previous regexp)))))
4398
+ (cl-pushnew regexp previous :test #'equal)))
4399
+ previous))
4402
4400
4403
4401
(defun markdown-complete-buffer ()
4404
4402
"Complete markup for all objects in the current buffer."
@@ -4442,8 +4440,7 @@ zero. Otherwise, cycle back to a level six atx header. Assumes
4442
4440
match data is available for `markdown-regex-header-setext'."
4443
4441
(let* ((char (char-after (match-beginning 2)))
4444
4442
(old-level (if (char-equal char ?=) 1 2))
4445
- (new-level (+ old-level arg))
4446
- (text (match-string 1)))
4443
+ (new-level (+ old-level arg)))
4447
4444
(when (and (not remove) (= new-level 0))
4448
4445
(setq new-level 6))
4449
4446
(cond
@@ -4708,7 +4705,7 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
4708
4705
(setcdr cur-alist alist)
4709
4706
(setq cur-alist alist))
4710
4707
((< cur-level level) ; first child
4711
- (dotimes (i (- level cur-level 1))
4708
+ (dotimes (_ (- level cur-level 1))
4712
4709
(setq alist (list (cons empty-heading alist))))
4713
4710
(if cur-alist
4714
4711
(let* ((parent (car cur-alist))
@@ -4719,7 +4716,7 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
4719
4716
(setq cur-level level))
4720
4717
(t ; new sibling of an ancestor
4721
4718
(let ((sibling-alist (last (cdr root))))
4722
- (dotimes (i (1- level))
4719
+ (dotimes (_ (1- level))
4723
4720
(setq sibling-alist (last (cdar sibling-alist))))
4724
4721
(setcdr sibling-alist alist)
4725
4722
(setq cur-alist alist))
@@ -4778,7 +4775,7 @@ the link, and line is the line number on which the link appears."
4778
4775
(match-string-no-properties 2)))
4779
4776
(start (match-beginning 0))
4780
4777
(line (markdown-line-number-at-pos)))
4781
- (add-to-list 'links (list text start line)))))
4778
+ (cl-pushnew (list text start line) links :test #'equal ))))
4782
4779
links))
4783
4780
4784
4781
(defun markdown-get-undefined-refs ()
@@ -4799,11 +4796,12 @@ For example, an alist corresponding to [Nice editor][Emacs] at line 12,
4799
4796
(unless (markdown-reference-definition target)
4800
4797
(let ((entry (assoc target missing)))
4801
4798
(if (not entry)
4802
- (add-to-list 'missing (cons target
4803
- (list (cons text (markdown-line-number-at-pos)))) t)
4799
+ (cl-pushnew
4800
+ (cons target (list (cons text (markdown-line-number-at-pos))))
4801
+ missing :test #'equal)
4804
4802
(setcdr entry
4805
4803
(append (cdr entry) (list (cons text (markdown-line-number-at-pos))))))))))
4806
- missing)))
4804
+ (reverse missing) )))
4807
4805
4808
4806
(defconst markdown-reference-check-buffer
4809
4807
"*Undefined references for %buffer%*"
@@ -5638,7 +5636,7 @@ See `markdown-cycle-atx', `markdown-cycle-setext', and
5638
5636
(markdown-cycle-hr -1))
5639
5637
;; Promote list item
5640
5638
((setq bounds (markdown-cur-list-item-bounds))
5641
- (markdown-promote-list-item))
5639
+ (markdown-promote-list-item bounds ))
5642
5640
;; Promote bold
5643
5641
((thing-at-point-looking-at markdown-regex-bold)
5644
5642
(markdown-cycle-bold))
@@ -5666,7 +5664,7 @@ See `markdown-cycle-atx', `markdown-cycle-setext', and
5666
5664
(markdown-cycle-hr 1))
5667
5665
;; Demote list item
5668
5666
((setq bounds (markdown-cur-list-item-bounds))
5669
- (markdown-demote-list-item))
5667
+ (markdown-demote-list-item bounds ))
5670
5668
;; Demote bold
5671
5669
((thing-at-point-looking-at markdown-regex-bold)
5672
5670
(markdown-cycle-bold))
@@ -5790,7 +5788,8 @@ Standalone XHTML output is identified by an occurrence of
5790
5788
When OUTPUT-BUFFER-NAME is given, insert the output in the buffer with
5791
5789
that name."
5792
5790
(interactive)
5793
- (browse-url-of-buffer (markdown-standalone markdown-output-buffer-name)))
5791
+ (browse-url-of-buffer
5792
+ (markdown-standalone (or output-buffer-name markdown-output-buffer-name))))
5794
5793
5795
5794
(defun markdown-export-file-name (&optional extension)
5796
5795
"Attempt to generate a filename for Markdown output.
@@ -6370,7 +6369,7 @@ before regenerating font-lock rules for extensions."
6370
6369
:type 'markdown-gfm-checkbox-button))))))
6371
6370
6372
6371
;; Called when any modification is made to buffer text.
6373
- (defun markdown-gfm-checkbox-after-change-function (beg end old-len )
6372
+ (defun markdown-gfm-checkbox-after-change-function (beg end _ )
6374
6373
"Add to `after-change-functions' to setup GFM checkboxes as buttons."
6375
6374
(save-excursion
6376
6375
(save-match-data
0 commit comments