Skip to content

Commit acd2c4c

Browse files
committed
Merge pull request #97 from cosmicexplorer/fix/use-lexical-binding
use lexical binding and fix byte-compile warnings
2 parents a4a9bb1 + ea0e534 commit acd2c4c

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

markdown-mode.el

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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; -*-
22

33
;; Copyright (C) 2007-2016 Jason R. Blevins <[email protected]>
44
;; Copyright (C) 2007, 2009 Edward O'Connor <[email protected]>
@@ -1441,10 +1441,10 @@ Function is called repeatedly until it returns nil. For details, see
14411441
(unless (and (eq new-start start) (eq new-end end))
14421442
(cons new-start new-end)))))
14431443

1444-
(defun markdown-font-lock-extend-region-function (start end old-len)
1444+
(defun markdown-font-lock-extend-region-function (start end _)
14451445
"Used in `jit-lock-after-change-extend-region-functions'. Delegates to
14461446
`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."
14481448
(let ((res (markdown-syntax-propertize-extend-region start end)))
14491449
(when res
14501450
(setq jit-lock-start (car res)
@@ -1455,7 +1455,7 @@ region to refontify, and OLD-LEN is the length of the region."
14551455
(save-excursion
14561456
(goto-char start)
14571457
(let ((levels (markdown-calculate-list-levels))
1458-
indent pre-regexp close-regexp open close stop)
1458+
indent pre-regexp close-regexp open close)
14591459
(while (and (< (point) end) (not close))
14601460
;; Search for a region with sufficient indentation
14611461
(if (null levels)
@@ -1829,7 +1829,6 @@ start which was previously propertized."
18291829
(save-excursion
18301830
(goto-char start)
18311831
(cl-loop
1832-
with skip = nil
18331832
while (re-search-forward markdown-regex-multimarkdown-metadata end t)
18341833
do (when (get-text-property (match-beginning 0)
18351834
'markdown-yaml-metadata-section)
@@ -2592,14 +2591,14 @@ upon failure."
25922591
"Search forward from point for the next list item with indentation LEVEL.
25932592
Set point to the beginning of the item, and return point, or nil
25942593
upon failure."
2595-
(let (bounds indent prev next)
2594+
(let (bounds indent next)
25962595
(setq next (point))
25972596
(forward-line)
25982597
(setq indent (markdown-cur-line-indent))
25992598
(while
26002599
(cond
26012600
;; Stop at end of the buffer.
2602-
((eobp) (setq prev nil))
2601+
((eobp) nil)
26032602
;; Continue if the current line is blank
26042603
((markdown-cur-line-blank-p) t)
26052604
;; List item
@@ -2734,8 +2733,8 @@ intact additional processing."
27342733
(let (refs)
27352734
(while (re-search-forward markdown-regex-reference-definition nil t)
27362735
(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))))
27392738

27402739
(defun markdown-code-at-point-p ()
27412740
"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'."
27882787
"Return t if PROP from BEGIN to END is equal to one of the given VALUES.
27892788
Also returns t if PROP is a list containing one of the VALUES.
27902789
Return nil otherwise."
2791-
(let (loc props val)
2790+
(let (props)
27922791
(catch 'found
27932792
(dolist (loc (number-sequence begin end))
27942793
(when (setq props (get-char-property loc prop))
@@ -3018,11 +3017,9 @@ into a variable to allow for dynamic let-binding.")
30183017
(enclosing-header
30193018
(cl-find-if ; just take first if multiple
30203019
(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)))))
30263023
header-bounds))
30273024
(header-begin
30283025
(when enclosing-header (cl-second (cl-first enclosing-header))))
@@ -3607,7 +3604,7 @@ Also see `markdown-pre-indentation'."
36073604
(goto-char loc)
36083605
(let* ((list-level (length (markdown-calculate-list-levels)))
36093606
(indent ""))
3610-
(dotimes (count list-level indent)
3607+
(dotimes (_ list-level indent)
36113608
(setq indent (concat indent " "))))))
36123609

36133610
(defun markdown-insert-blockquote ()
@@ -3663,7 +3660,7 @@ Also see `markdown-blockquote-indentation'."
36633660
(goto-char loc)
36643661
(let* ((list-level (length (markdown-calculate-list-levels)))
36653662
indent)
3666-
(dotimes (count (1+ list-level) indent)
3663+
(dotimes (_ (1+ list-level) indent)
36673664
(setq indent (concat indent " "))))))
36683665

36693666
(defun markdown-insert-pre ()
@@ -4060,7 +4057,7 @@ addresses, bold, italics, reference definition (add URI to kill
40604057
ring), footnote markers and text (kill both marker and text, add
40614058
text to kill ring), and list items."
40624059
(interactive "*")
4063-
(let (val tmp)
4060+
(let (val)
40644061
(cond
40654062
;; Inline code
40664063
((markdown-code-at-point-p)
@@ -4254,7 +4251,7 @@ See `markdown-indent-line' and `markdown-indent-line'."
42544251
(defun markdown-exdent-region (beg end)
42554252
"Call `markdown-indent-region' on region from BEG to END with prefix."
42564253
(interactive "*r")
4257-
(markdown-indent-region (region-beginning) (region-end) t))
4254+
(markdown-indent-region beg end t))
42584255

42594256

42604257
;;; Markup Completion =========================================================
@@ -4398,7 +4395,8 @@ match."
43984395
(or match (setq match (looking-back prev-regexp nil)))))
43994396
(unless match
44004397
(save-excursion (funcall function))))))
4401-
(add-to-list 'previous regexp)))))
4398+
(cl-pushnew regexp previous :test #'equal)))
4399+
previous))
44024400

44034401
(defun markdown-complete-buffer ()
44044402
"Complete markup for all objects in the current buffer."
@@ -4442,8 +4440,7 @@ zero. Otherwise, cycle back to a level six atx header. Assumes
44424440
match data is available for `markdown-regex-header-setext'."
44434441
(let* ((char (char-after (match-beginning 2)))
44444442
(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)))
44474444
(when (and (not remove) (= new-level 0))
44484445
(setq new-level 6))
44494446
(cond
@@ -4708,7 +4705,7 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
47084705
(setcdr cur-alist alist)
47094706
(setq cur-alist alist))
47104707
((< cur-level level) ; first child
4711-
(dotimes (i (- level cur-level 1))
4708+
(dotimes (_ (- level cur-level 1))
47124709
(setq alist (list (cons empty-heading alist))))
47134710
(if cur-alist
47144711
(let* ((parent (car cur-alist))
@@ -4719,7 +4716,7 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
47194716
(setq cur-level level))
47204717
(t ; new sibling of an ancestor
47214718
(let ((sibling-alist (last (cdr root))))
4722-
(dotimes (i (1- level))
4719+
(dotimes (_ (1- level))
47234720
(setq sibling-alist (last (cdar sibling-alist))))
47244721
(setcdr sibling-alist alist)
47254722
(setq cur-alist alist))
@@ -4778,7 +4775,7 @@ the link, and line is the line number on which the link appears."
47784775
(match-string-no-properties 2)))
47794776
(start (match-beginning 0))
47804777
(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))))
47824779
links))
47834780

47844781
(defun markdown-get-undefined-refs ()
@@ -4799,11 +4796,12 @@ For example, an alist corresponding to [Nice editor][Emacs] at line 12,
47994796
(unless (markdown-reference-definition target)
48004797
(let ((entry (assoc target missing)))
48014798
(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)
48044802
(setcdr entry
48054803
(append (cdr entry) (list (cons text (markdown-line-number-at-pos))))))))))
4806-
missing)))
4804+
(reverse missing))))
48074805

48084806
(defconst markdown-reference-check-buffer
48094807
"*Undefined references for %buffer%*"
@@ -5638,7 +5636,7 @@ See `markdown-cycle-atx', `markdown-cycle-setext', and
56385636
(markdown-cycle-hr -1))
56395637
;; Promote list item
56405638
((setq bounds (markdown-cur-list-item-bounds))
5641-
(markdown-promote-list-item))
5639+
(markdown-promote-list-item bounds))
56425640
;; Promote bold
56435641
((thing-at-point-looking-at markdown-regex-bold)
56445642
(markdown-cycle-bold))
@@ -5666,7 +5664,7 @@ See `markdown-cycle-atx', `markdown-cycle-setext', and
56665664
(markdown-cycle-hr 1))
56675665
;; Demote list item
56685666
((setq bounds (markdown-cur-list-item-bounds))
5669-
(markdown-demote-list-item))
5667+
(markdown-demote-list-item bounds))
56705668
;; Demote bold
56715669
((thing-at-point-looking-at markdown-regex-bold)
56725670
(markdown-cycle-bold))
@@ -5790,7 +5788,8 @@ Standalone XHTML output is identified by an occurrence of
57905788
When OUTPUT-BUFFER-NAME is given, insert the output in the buffer with
57915789
that name."
57925790
(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))))
57945793

57955794
(defun markdown-export-file-name (&optional extension)
57965795
"Attempt to generate a filename for Markdown output.
@@ -6370,7 +6369,7 @@ before regenerating font-lock rules for extensions."
63706369
:type 'markdown-gfm-checkbox-button))))))
63716370

63726371
;; 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 _)
63746373
"Add to `after-change-functions' to setup GFM checkboxes as buttons."
63756374
(save-excursion
63766375
(save-match-data

0 commit comments

Comments
 (0)