Skip to content
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

Fix byte-compiler warnings of calls to deprecated functions or missing declarations. #107

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 19 additions & 10 deletions origami-parsers.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@
;;; Commentary:

;;; Code:
(require 'cl)
(require 'cl-lib)
(require 'dash)
(require 's)

;; The following prevent end-of-data byte-compiler warnings:
;; these functions are defined in origami.el but can require origami
;; because origami already requires origami-parsers.
(declare-function origami-fold-children "origami")
(declare-function origami-fold-shallow-merge "origami")
(declare-function origami-fold-root-node "origami")

(defun origami-get-positions (content regex)
"Returns a list of positions where REGEX matches in CONTENT. A
Expand Down Expand Up @@ -95,7 +103,7 @@ position in the CONTENT."
;; complexity here is due to having to find the end of the children so that the
;; parent encompasses them
(-reduce-r-from (lambda (nodes acc)
(destructuring-bind (children-end . children) (build-nodes (cdr nodes))
(cl-destructuring-bind (children-end . children) (build-nodes (cdr nodes))
(let ((this-end (max children-end (end (car nodes)))))
(cons (max this-end (car acc))
(cons (funcall create
Expand Down Expand Up @@ -156,13 +164,13 @@ position in the CONTENT."
(defun origami-c-style-parser (create)
(lambda (content)
(let ((positions (->> (origami-get-positions content "[{}]")
(remove-if (lambda (position)
(let ((face (get-text-property 0 'face (car position))))
(-any? (lambda (f)
(memq f '(font-lock-doc-face
font-lock-comment-face
font-lock-string-face)))
(if (listp face) face (list face)))))))))
(cl-remove-if (lambda (position)
(let ((face (get-text-property 0 'face (car position))))
(-any? (lambda (f)
(memq f '(font-lock-doc-face
font-lock-comment-face
font-lock-string-face)))
(if (listp face) face (list face)))))))))
(origami-build-pair-tree create "{" "}" positions))))

(defun origami-c-macro-parser (create)
Expand Down Expand Up @@ -206,6 +214,7 @@ position in the CONTENT."
acc))
(goto-char new-end)))
acc))
(declare-function python-subparser "origami-parsers") ; prevent byte-compiler warning
(python-subparser (point-min) (point-max)))))

(defun origami-lisp-parser (create regex)
Expand All @@ -228,7 +237,7 @@ position in the CONTENT."
(reverse acc)))))

(defun origami-elisp-parser (create)
(origami-lisp-parser create "(def\\w*\\s-*\\(\\s_\\|\\w\\|[:?!]\\)*\\([ \\t]*(.*?)\\)?"))
(origami-lisp-parser create "(\\(?:cl-\\)?def\\w*\\s-*\\(\\s_\\|\\w\\|[:?!]\\)*\\([ \\t]*(.*?)\\)?"))

(defun origami-clj-parser (create)
(origami-lisp-parser create "(def\\(\\w\\|-\\)*\\s-*\\(\\s_\\|\\w\\|[?!]\\)*\\([ \\t]*\\[.*?\\]\\)?"))
Expand Down
18 changes: 13 additions & 5 deletions origami.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ header overlay should cover. Result is a cons cell of (begin . end)."
(let ((range (origami-header-overlay-range fold-ov)))
(move-overlay header-overlay (car range) (cdr range)))))

(defun origami-header-modify-hook (header-overlay after-p b e &optional l)
(defun origami-header-modify-hook (header-overlay after-p _b _e &optional _l)
(if after-p (origami-header-overlay-reset-position header-overlay)))

(defun origami-create-overlay (beg end offset buffer)
Expand Down Expand Up @@ -157,7 +157,7 @@ header overlay should cover. Result is a cons cell of (begin . end)."
(overlay-put ov 'before-string nil)
(overlay-put ov 'after-string nil))

(defun origami-isearch-show (ov)
(defun origami-isearch-show (_ov)
(origami-show-node (current-buffer) (point)))

(defun origami-hide-overlay-from-fold-tree-fn (node)
Expand Down Expand Up @@ -273,7 +273,7 @@ header overlay should cover. Result is a cons cell of (begin . end)."
F applied to the leaf."
(cdr
(-reduce-r-from (lambda (node acc)
(destructuring-bind (old-node . new-node) acc
(cl-destructuring-bind (old-node . new-node) acc
(cons node (origami-fold-replace-child node old-node new-node))))
(let ((leaf (-last-item path))) (cons leaf (funcall f leaf)))
(butlast path))))
Expand Down Expand Up @@ -432,6 +432,12 @@ with the current state and the current node at each iteration."

;;; interactive utils

;; The following defvar prevent byte compiler warnings.
;; It would be better to replace the code with defvar-local forms
;; but that was introduced in Emacs 24.3 and this package supports Emacs 24.
(defvar origami-history) ; prevent byte-compiler warning
(defvar origami-tree-tick) ; prevent byte-compiler warning

(defun origami-setup-local-vars (buffer)
(with-current-buffer buffer
(set (make-local-variable 'origami-history)
Expand Down Expand Up @@ -491,6 +497,8 @@ was last built."
'origami-indent-parser))
(funcall parser-gen create))))

(defvar origami-mode) ; forward declaration to prevent byte-compiler warning

(defun origami-get-fold-tree (buffer)
"Facade. Build the tree if it hasn't already been built
otherwise fetch cached tree."
Expand All @@ -499,7 +507,7 @@ otherwise fetch cached tree."
(origami-build-tree buffer (origami-get-parser buffer))
(origami-get-cached-tree buffer))))

(defun origami-apply-new-tree (buffer old-tree new-tree)
(defun origami-apply-new-tree (_buffer old-tree new-tree)
(when new-tree
(origami-fold-diff old-tree new-tree
'origami-hide-overlay-from-fold-tree-fn
Expand Down Expand Up @@ -802,7 +810,7 @@ Lastly, the normal hook `origami-mode-hook' is run using
Key bindings:
\\{origami-mode-map}"
:group 'origami
:lighter nil
:lighter ""
:keymap origami-mode-map
:init-value nil
(if origami-mode
Expand Down