Skip to content

Commit

Permalink
barf-p, singleton-p, and fix package-lint once and for all
Browse files Browse the repository at this point in the history
  • Loading branch information
dickmao committed Nov 7, 2019
1 parent db39d4e commit 63b0000
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 73 deletions.
2 changes: 2 additions & 0 deletions Cask
@@ -1,10 +1,12 @@
(source gnu)
(source melpa)

(package-file "magit-patch-changelog.el")
(files "magit-patch-changelog.el")

(development
(depends-on "magit")
(depends-on "package-lint")
(depends-on "ecukes")
(depends-on "anaphora")
(depends-on "f")
Expand Down
58 changes: 39 additions & 19 deletions magit-patch-changelog.el
Expand Up @@ -338,7 +338,23 @@ Move (foo, >b< ar) to (foo)\n(bar)."
(nextp (and nextm (funcall next-line-p (marker-position nextm))))
(limit-func (lambda () (if (< direction 0)
(line-beginning-position)
(line-end-position)))))
(line-end-position))))
(singleton-p (lambda ()
(and (not (save-excursion
(magit-patch-changelog--goto-ref
-1 (line-beginning-position))))
(not (save-excursion
(magit-patch-changelog--goto-ref
1 (line-end-position)))))))
(barf-p (lambda ()
(or (and (< direction 0)
(not (save-excursion
(magit-patch-changelog--goto-ref
-1 (line-beginning-position)))))
(and (> direction 0)
(not (save-excursion
(magit-patch-changelog--goto-ref
1 (line-end-position)))))))))
(cl-macrolet ((jimmy
(goback)
`(progn
Expand All @@ -350,30 +366,34 @@ Move (foo, >b< ar) to (foo)\n(bar)."
;; the wrong purposes. To remember a location for internal use,
;; store it in a Lisp variable."
(let ((goback (copy-marker (point))))
(cond ((not next)
(cond ((and (< direction 0) header-tail)
(apply #'kill-region (list (car bounds) (cdr bounds)))
(goto-char header-tail)
(funcall insert-func changelog-ref)
(magit-patch-changelog--fixline changelog-ref)
(jimmy goback))
((and (> direction 0)
(save-excursion
(magit-patch-changelog--goto-ref
-1 (line-beginning-position))))
(apply #'kill-region (list (car bounds) (cdr bounds)))
(end-of-line)
(insert "\n")
(funcall insert-func changelog-ref)
(magit-patch-changelog--fixline changelog-ref)
(jimmy goback))))
(cond ((and (not next) (funcall singleton-p)))
((and (not next) (< direction 0)) ;; special case header fixup
(when header-tail
(apply #'kill-region (list (car bounds) (cdr bounds)))
(goto-char header-tail)
(funcall insert-func changelog-ref)
(magit-patch-changelog--fixline changelog-ref)
(jimmy goback)))
((and (funcall barf-p) (not (funcall singleton-p)))
(apply #'kill-region (list (car bounds) (cdr bounds)))
(if (< direction 0)
(progn (beginning-of-line)
(insert "\n")
(forward-line -1)
(backward-char))
(end-of-line)
(insert "\n"))
(funcall insert-func changelog-ref)
(magit-patch-changelog--fixline changelog-ref)
(jimmy goback))
(t
(apply #'kill-region (list (car bounds) (cdr bounds)))
(goto-char (marker-position nextm))
(unless nextp
(goto-char (or (magit-patch-changelog--single-property-change
'magit-patch-changelog-loc
(marker-position nextm) direction (funcall limit-func))
(marker-position nextm) direction
(funcall limit-func))
(funcall limit-func))))
(funcall insert-func changelog-ref)
(magit-patch-changelog--fixline changelog-ref)
Expand Down
79 changes: 25 additions & 54 deletions tools/package-lint.sh
@@ -1,59 +1,30 @@
#!/bin/sh -ex

# The following is a derivative work of
# https://github.com/purcell/package-lint
# licensed under GNU General Public License v3.0.

EMACS="${EMACS:=emacs}"

INIT_PACKAGE_EL="(progn
(require 'package)
(package-initialize)
(push (quote (\"melpa\" . \"http://melpa.org/packages/\")) package-archives)
(package-refresh-contents)
(unless (package-installed-p (quote package-lint))
(package-install (quote package-lint))))"

# rm -rf "$HOME"/.emacs.d/elpa/package-lint-*

# Get mainline package-lint, then replace package-lint.el with dickmao's.
# quelpa doesn't get data/stdlib-changes.gz for whatever reason.
#( cd /tmp ; curl -OskL https://raw.githubusercontent.com/dickmao/package-lint/datetime/package-lint.el )
#"$EMACS" -Q -batch \
# --eval "$INIT_PACKAGE_EL" \
# --eval "(let ((dir (file-name-directory (locate-library \"package-lint\")))) \
# (ignore-errors (delete-file (expand-file-name \"package-lint.elc\" dir))) \
# (copy-file (expand-file-name \"package-lint.el\" \
# \"/tmp\") (expand-file-name \"package-lint.el\" dir) t))"

BASENAME=$(basename "$1")
"$EMACS" -Q -batch \
--eval "$INIT_PACKAGE_EL" \
-l package-lint.el \
--visit "$1" \
--eval "(checkdoc-eval-current-buffer)" \
--eval "(princ (with-current-buffer checkdoc-diagnostic-buffer (buffer-string)))" \
2>&1 | egrep -a "^$BASENAME:" | egrep -v "Messages should start" && [ -n "${EMACS_LINT_IGNORE+x}" ]

# Lint ourselves
# Lint failures are ignored if EMACS_LINT_IGNORE is defined, so that lint
# failures on Emacs 24.2 and below don't cause the tests to fail, as these
# versions have buggy imenu that reports (defvar foo) as a definition of foo.
# Reduce purity via:
# --eval "(fset 'package-lint--check-defs-prefix (symbol-function 'ignore))" \
"$EMACS" -Q -batch \
--eval "$INIT_PACKAGE_EL" \
-l package-lint.el \
--eval "(defconst package-lint--sane-prefixes \
(rx \
string-start \
(or \
\"org-dblock-write:\" \
\"string-trim-left\" \
\"org-babel-execute:\" \
\"org-babel-prep-session:\" \
\"org-babel-variable-assignments:\" \
\"org-babel-default-header-args:\" \
\"pcomplete/\")))" \
-f package-lint-batch-and-exit \
"$1" || [ -n "${EMACS_LINT_IGNORE+x}" ]
!( cask emacs -Q --batch \
--visit "$1" \
--eval "(checkdoc-eval-current-buffer)" \
--eval "(princ (with-current-buffer checkdoc-diagnostic-buffer \
(buffer-string)))" \
2>&1 | egrep -a "^$BASENAME:" | egrep -v "Messages should start" | grep "." )

cask emacs -Q --batch \
-l package-lint \
--eval "(package-initialize)" \
--eval "(push (quote (\"melpa\" . \"http://melpa.org/packages/\")) \
package-archives)" \
--eval "(package-refresh-contents)" \
--eval "(defconst package-lint--sane-prefixes \
(rx \
string-start \
(or \
\"org-dblock-write:\" \
\"string-trim-left\" \
\"org-babel-execute:\" \
\"org-babel-prep-session:\" \
\"org-babel-variable-assignments:\" \
\"org-babel-default-header-args:\" \
\"pcomplete/\")))" \
-f package-lint-batch-and-exit "$1"

0 comments on commit 63b0000

Please sign in to comment.