瀏覽代碼

Correctly extract package and function documentation and test loading

a package into a sandboxed Emacs
master
Peter J. Jones 7 年之前
父節點
當前提交
2e17314292
共有 6 個文件被更改,包括 84 次插入6 次删除
  1. 2
    2
      defpkg.sh
  2. 5
    0
      desc.sh
  3. 10
    4
      elpkg.mk
  4. 20
    0
      fdoc2md.el
  5. 31
    0
      fdoc2md.sh
  6. 16
    0
      pkgtest.el

+ 2
- 2
defpkg.sh 查看文件

@@ -5,8 +5,8 @@ NAME=$1
ELFILE=$2
ELPKG=`dirname $0`
VERSION=`$ELPKG/version.sh $ELFILE`
DESC=`head -1 $ELFILE | sed -E 's/^.*-- *//'`
DEPS=`[ -r deps.el ] && cat deps.el`
DESC=`$ELPKG/desc.sh $ELFILE`
DEPS=`[ -r deps.el ] && cat deps.el` # FIXME: what file name to use?

###############################################################################
printf '(define-package "%s" "%s" "%s" %s)\n' \

+ 5
- 0
desc.sh 查看文件

@@ -0,0 +1,5 @@
#!/bin/sh

# Print the description from an *.el file.
egrep '^;;;.*--' $1 | \
sed -E 's/^.*-- *//'

+ 10
- 4
elpkg.mk 查看文件

@@ -9,13 +9,13 @@ EL_FILES ?= $(shell git ls-files|egrep '\.el$$')

################################################################################
EMACS = emacs
EMACS_FLAGS = -q --no-site-file --batch
EMACS_FLAGS = --batch -Q
EMACS_FLAGS += --eval "(add-to-list 'load-path \"lisp\")"
EMACS_FLAGS += -f package-initialize
EMACS_FLAGS += -f batch-byte-compile

################################################################################
.PHONEY: all clean compile
.PHONEY: all clean test compile

################################################################################
all: $(TARBALL)
@@ -25,12 +25,18 @@ compile: $(EL_FILES:.el=.elc)

################################################################################
clean:
rm -rf $(TARBALL) $(PACKAGE)
rm -rf $(TARBALL) $(PACKAGE) $(PACKAGE).elpa
rm -f $(EL_FILES:.el=.elc)

################################################################################
test: $(TARBALL)
$(EMACS) --batch -Q -l $(ELPKG)/pkgtest.el \
--eval '(elpkg-test-package "$(CURDIR)/$(TARBALL)")'

################################################################################
$(PACKAGE): $(PKG_FILES)
mkdir $@
rm -rf $@
mkdir -p $@
cp $(PKG_FILES) $@
$(ELPKG)/defpkg.sh $(NAME) $@/$(notdir $(CORE_FILE)) > $@/$(NAME)-pkg.el


+ 20
- 0
fdoc2md.el 查看文件

@@ -0,0 +1,20 @@
;;; -*- lexical-binding: t -*-
;;; fdoc2md.el -- Convert function documentation to markdown
(defvar fdoc-replacements
'(("`\\([^']+\\)'" . "`\\1`"))
"A list of alists where the car is the search regular
expression and the cdr is the replacement string.")

(defun fdoc2md (func file)
"Extract the documentation from FUNC and try to convert it to
markdown then append it to FILE."
(let ((doc (documentation func)))
(mapc (lambda (re)
(let ((start nil))
(while (setq start (string-match (car re) doc
(if start (match-end 0))))
(setq doc (replace-match (cdr re) nil nil doc nil)))))
fdoc-replacements)
(with-temp-buffer
(insert doc)
(append-to-file (point-min) (point-max) file))))

+ 31
- 0
fdoc2md.sh 查看文件

@@ -0,0 +1,31 @@
#!/bin/sh

################################################################################
# Extract documentation from an elisp function and put it on STDOUT.
#
# The first argument should be the name of a function for which you
# want documentation.
#
# Any remaining arguments are elisp files that should be loaded by
# Emacs so their documentation can be read.

################################################################################
ELPKG=`dirname $0`
TEMPF=`mktemp`
EMACS=emacs
FUNC=$1

################################################################################
loads () {
for f in "$@"; do
echo "-l $f"
done
}

################################################################################
shift
${EMACS} --batch -Q -l $ELPKG/fdoc2md.el `loads "$@"` \
--eval "(fdoc2md '$FUNC \"$TEMPF\")" > /dev/null 2>&1

cat $TEMPF
rm -f $TEMPF

+ 16
- 0
pkgtest.el 查看文件

@@ -0,0 +1,16 @@
;;; -*- lexical-binding: t -*-
;;; pkgtest.el -- Install a test package into a clean Emacs
(require 'package)

(defun elpkg-test-package (tarball)
"Load the given tarball into a fake package store."
(let ((package-user-dir (concat (file-name-sans-extension tarball) ".elpa"))
(package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/"))))
(toggle-debug-on-error)
(package-initialize)
(package-install-file tarball)
;; TODO: check for tests and run:
;; (ert-run-tests-batch-and-exit)
))

Loading…
取消
儲存