Skip to content

use lexical binding and fix byte-compile warnings #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions markdown-mode.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; markdown-mode.el --- Emacs Major mode for Markdown-formatted text files
;;; markdown-mode.el --- Emacs Major mode for Markdown-formatted text files -*- lexical-binding: t; -*-

;; Copyright (C) 2007-2016 Jason R. Blevins <[email protected]>
;; Copyright (C) 2007, 2009 Edward O'Connor <[email protected]>
Expand Down Expand Up @@ -1381,7 +1381,7 @@ Function is called repeatedly until it returns nil. For details, see
(save-excursion
(goto-char start)
(let ((levels (markdown-calculate-list-levels))
indent pre-regexp close-regexp open close stop)
indent pre-regexp close-regexp open close)
(while (and (< (point) end) (not close))
;; Search for a region with sufficient indentation
(if (null levels)
Expand Down Expand Up @@ -2196,14 +2196,14 @@ upon failure."
"Search forward from point for the next list item with indentation LEVEL.
Set point to the beginning of the item, and return point, or nil
upon failure."
(let (bounds indent prev next)
(let (bounds indent next)
(setq next (point))
(forward-line)
(setq indent (markdown-cur-line-indent))
(while
(cond
;; Stop at end of the buffer.
((eobp) (setq prev nil))
((eobp) nil)
;; Continue if the current line is blank
((markdown-cur-line-blank-p) t)
;; List item
Expand Down Expand Up @@ -2338,8 +2338,8 @@ intact additional processing."
(let (refs)
(while (re-search-forward markdown-regex-reference-definition nil t)
(let ((target (match-string-no-properties 2)))
(add-to-list 'refs target t)))
refs)))
(cl-pushnew target refs :test #'equal)))
(reverse refs))))

(defun markdown-code-at-point-p ()
"Return non-nil if the point is at an inline code fragment.
Expand Down Expand Up @@ -2388,7 +2388,7 @@ GFM quoted code blocks. Calls `markdown-code-block-at-pos'."
"Return t if PROP from BEGIN to END is equal to one of the given VALUES.
Also returns t if PROP is a list containing one of the VALUES.
Return nil otherwise."
(let (loc props val)
(let (props)
(catch 'found
(dolist (loc (number-sequence begin end))
(when (setq props (get-char-property loc prop))
Expand Down Expand Up @@ -3116,7 +3116,7 @@ Also see `markdown-pre-indentation'."
(goto-char loc)
(let* ((list-level (length (markdown-calculate-list-levels)))
(indent ""))
(dotimes (count list-level indent)
(dotimes (_ list-level indent)
(setq indent (concat indent " "))))))

(defun markdown-insert-blockquote ()
Expand Down Expand Up @@ -3172,7 +3172,7 @@ Also see `markdown-blockquote-indentation'."
(goto-char loc)
(let* ((list-level (length (markdown-calculate-list-levels)))
indent)
(dotimes (count (1+ list-level) indent)
(dotimes (_ (1+ list-level) indent)
(setq indent (concat indent " "))))))

(defun markdown-insert-pre ()
Expand Down Expand Up @@ -3553,7 +3553,7 @@ addresses, bold, italics, reference definition (add URI to kill
ring), footnote markers and text (kill both marker and text, add
text to kill ring), and list items."
(interactive "*")
(let (val tmp)
(let (val)
(cond
;; Inline code
((markdown-code-at-point-p)
Expand Down Expand Up @@ -3747,7 +3747,7 @@ See `markdown-indent-line' and `markdown-indent-line'."
(defun markdown-exdent-region (beg end)
"Call `markdown-indent-region' on region from BEG to END with prefix."
(interactive "*r")
(markdown-indent-region (region-beginning) (region-end) t))
(markdown-indent-region beg end t))


;;; Markup Completion =========================================================
Expand Down Expand Up @@ -3891,7 +3891,8 @@ match."
(or match (setq match (looking-back prev-regexp nil)))))
(unless match
(save-excursion (funcall function))))))
(add-to-list 'previous regexp)))))
(cl-pushnew regexp previous :test #'equal)))
previous))

(defun markdown-complete-buffer ()
"Complete markup for all objects in the current buffer."
Expand Down Expand Up @@ -3935,8 +3936,7 @@ zero. Otherwise, cycle back to a level six atx header. Assumes
match data is available for `markdown-regex-header-setext'."
(let* ((char (char-after (match-beginning 2)))
(old-level (if (char-equal char ?=) 1 2))
(new-level (+ old-level arg))
(text (match-string 1)))
(new-level (+ old-level arg)))
(when (and (not remove) (= new-level 0))
(setq new-level 6))
(cond
Expand Down Expand Up @@ -4199,7 +4199,7 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
(setcdr cur-alist alist)
(setq cur-alist alist))
((< cur-level level) ; first child
(dotimes (i (- level cur-level 1))
(dotimes (_ (- level cur-level 1))
(setq alist (list (cons empty-heading alist))))
(if cur-alist
(let* ((parent (car cur-alist))
Expand All @@ -4210,7 +4210,7 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
(setq cur-level level))
(t ; new sibling of an ancestor
(let ((sibling-alist (last (cdr root))))
(dotimes (i (1- level))
(dotimes (_ (1- level))
(setq sibling-alist (last (cdar sibling-alist))))
(setcdr sibling-alist alist)
(setq cur-alist alist))
Expand Down Expand Up @@ -4258,7 +4258,7 @@ the link, and line is the line number on which the link appears."
(match-string-no-properties 2)))
(start (match-beginning 0))
(line (markdown-line-number-at-pos)))
(add-to-list 'links (list text start line)))))
(cl-pushnew (list text start line) links :test #'equal))))
links))

(defun markdown-get-undefined-refs ()
Expand All @@ -4279,11 +4279,12 @@ For example, an alist corresponding to [Nice editor][Emacs] at line 12,
(unless (markdown-reference-definition target)
(let ((entry (assoc target missing)))
(if (not entry)
(add-to-list 'missing (cons target
(list (cons text (markdown-line-number-at-pos)))) t)
(cl-pushnew
(cons target (list (cons text (markdown-line-number-at-pos))))
missing :test #'equal)
(setcdr entry
(append (cdr entry) (list (cons text (markdown-line-number-at-pos))))))))))
missing)))
(reverse missing))))

(defconst markdown-reference-check-buffer
"*Undefined references for %buffer%*"
Expand Down Expand Up @@ -4864,9 +4865,8 @@ Only visible heading lines are considered, unless INVISIBLE-OK is non-nil."

(defalias 'markdown-end-of-heading 'outline-end-of-heading)

(defun markdown-on-heading-p (&optional invisible-ok)
"Return t if point is on a (visible) heading line.
If INVISIBLE-OK is non-nil, an invisible heading line is ok too."
(defun markdown-on-heading-p ()
"Return t if point is on a (visible) heading line."
(get-text-property (point) 'markdown-heading))

(defun markdown-end-of-subtree (&optional invisible-OK)
Expand Down Expand Up @@ -5065,7 +5065,7 @@ See `markdown-cycle-atx', `markdown-cycle-setext', and
(markdown-cycle-hr -1))
;; Promote list item
((setq bounds (markdown-cur-list-item-bounds))
(markdown-promote-list-item))
(markdown-promote-list-item bounds))
;; Promote bold
((thing-at-point-looking-at markdown-regex-bold)
(markdown-cycle-bold))
Expand Down Expand Up @@ -5093,7 +5093,7 @@ See `markdown-cycle-atx', `markdown-cycle-setext', and
(markdown-cycle-hr 1))
;; Demote list item
((setq bounds (markdown-cur-list-item-bounds))
(markdown-demote-list-item))
(markdown-demote-list-item bounds))
;; Demote bold
((thing-at-point-looking-at markdown-regex-bold)
(markdown-cycle-bold))
Expand Down Expand Up @@ -5212,7 +5212,8 @@ Standalone XHTML output is identified by an occurrence of
When OUTPUT-BUFFER-NAME is given, insert the output in the buffer with
that name."
(interactive)
(browse-url-of-buffer (markdown-standalone markdown-output-buffer-name)))
(browse-url-of-buffer
(markdown-standalone (or output-buffer-name markdown-output-buffer-name))))

(defun markdown-export-file-name (&optional extension)
"Attempt to generate a filename for Markdown output.
Expand Down Expand Up @@ -5572,11 +5573,9 @@ newline after."
(setq new-to (point)))
(cl-values new-from new-to)))

(defun markdown-check-change-for-wiki-link (from to change)
(defun markdown-check-change-for-wiki-link (from to _)
"Check region between FROM and TO for wiki links and re-fontfy as needed.
Designed to be used with the `after-change-functions' hook.
CHANGE is the number of bytes of pre-change text replaced by the
given range."
Designed to be used with the `after-change-functions' hook."
(interactive "nfrom: \nnto: \nnchange: ")
(let* ((modified (buffer-modified-p))
(buffer-undo-list t)
Expand Down Expand Up @@ -5786,7 +5785,7 @@ before regenerating font-lock rules for extensions."
:type 'markdown-gfm-checkbox-button))))))

;; Called when any modification is made to buffer text.
(defun markdown-gfm-checkbox-after-change-function (beg end old-len)
(defun markdown-gfm-checkbox-after-change-function (beg end _)
"Add to `after-change-functions' to setup GFM checkboxes as buttons."
(save-excursion
(save-match-data
Expand Down