Browse Source

Correctly extract package and function documentation and test loading

a package into a sandboxed Emacs
master
Peter J. Jones 6 years ago
parent
commit
2e17314292
6 changed files with 84 additions and 6 deletions
  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 View File

@@ -5,8 +5,8 @@ NAME=$1
5 5
 ELFILE=$2
6 6
 ELPKG=`dirname $0`
7 7
 VERSION=`$ELPKG/version.sh $ELFILE`
8
-DESC=`head -1 $ELFILE | sed -E 's/^.*-- *//'`
9
-DEPS=`[ -r deps.el ] && cat deps.el`
8
+DESC=`$ELPKG/desc.sh $ELFILE`
9
+DEPS=`[ -r deps.el ] && cat deps.el` # FIXME: what file name to use?
10 10
 
11 11
 ###############################################################################
12 12
 printf '(define-package "%s" "%s" "%s" %s)\n' \

+ 5
- 0
desc.sh View File

@@ -0,0 +1,5 @@
1
+#!/bin/sh
2
+
3
+# Print the description from an *.el file.
4
+egrep '^;;;.*--' $1 | \
5
+  sed -E 's/^.*-- *//'

+ 10
- 4
elpkg.mk View File

@@ -9,13 +9,13 @@ EL_FILES  ?= $(shell git ls-files|egrep '\.el$$')
9 9
 
10 10
 ################################################################################
11 11
 EMACS = emacs
12
-EMACS_FLAGS = -q --no-site-file --batch
12
+EMACS_FLAGS =  --batch -Q
13 13
 EMACS_FLAGS += --eval "(add-to-list 'load-path \"lisp\")"
14 14
 EMACS_FLAGS += -f package-initialize
15 15
 EMACS_FLAGS += -f batch-byte-compile
16 16
 
17 17
 ################################################################################
18
-.PHONEY: all clean compile
18
+.PHONEY: all clean test compile
19 19
 
20 20
 ################################################################################
21 21
 all: $(TARBALL)
@@ -25,12 +25,18 @@ compile: $(EL_FILES:.el=.elc)
25 25
 
26 26
 ################################################################################
27 27
 clean:
28
-	rm -rf $(TARBALL) $(PACKAGE)
28
+	rm -rf $(TARBALL) $(PACKAGE) $(PACKAGE).elpa
29 29
 	rm -f $(EL_FILES:.el=.elc)
30 30
 
31
+################################################################################
32
+test: $(TARBALL)
33
+	$(EMACS) --batch -Q -l $(ELPKG)/pkgtest.el \
34
+	  --eval '(elpkg-test-package "$(CURDIR)/$(TARBALL)")'
35
+
31 36
 ################################################################################
32 37
 $(PACKAGE): $(PKG_FILES)
33
-	mkdir $@
38
+	rm -rf $@
39
+	mkdir -p $@
34 40
 	cp $(PKG_FILES) $@
35 41
 	$(ELPKG)/defpkg.sh $(NAME) $@/$(notdir $(CORE_FILE)) > $@/$(NAME)-pkg.el
36 42
 

+ 20
- 0
fdoc2md.el View File

@@ -0,0 +1,20 @@
1
+;;; -*- lexical-binding: t -*-
2
+;;; fdoc2md.el -- Convert function documentation to markdown
3
+(defvar fdoc-replacements
4
+  '(("`\\([^']+\\)'" . "`\\1`"))
5
+  "A list of alists where the car is the search regular
6
+expression and the cdr is the replacement string.")
7
+
8
+(defun fdoc2md (func file)
9
+  "Extract the documentation from FUNC and try to convert it to
10
+markdown then append it to FILE."
11
+  (let ((doc (documentation func)))
12
+    (mapc (lambda (re)
13
+            (let ((start nil))
14
+              (while (setq start (string-match (car re) doc
15
+                                               (if start (match-end 0))))
16
+                     (setq doc (replace-match (cdr re) nil nil doc nil)))))
17
+            fdoc-replacements)
18
+    (with-temp-buffer
19
+      (insert doc)
20
+      (append-to-file (point-min) (point-max) file))))

+ 31
- 0
fdoc2md.sh View File

@@ -0,0 +1,31 @@
1
+#!/bin/sh
2
+
3
+################################################################################
4
+# Extract documentation from an elisp function and put it on STDOUT.
5
+#
6
+# The first argument should be the name of a function for which you
7
+# want documentation.
8
+#
9
+# Any remaining arguments are elisp files that should be loaded by
10
+# Emacs so their documentation can be read.
11
+
12
+################################################################################
13
+ELPKG=`dirname $0`
14
+TEMPF=`mktemp`
15
+EMACS=emacs
16
+FUNC=$1
17
+
18
+################################################################################
19
+loads () {
20
+  for f in "$@"; do
21
+    echo "-l $f"
22
+  done
23
+}
24
+
25
+################################################################################
26
+shift
27
+${EMACS} --batch -Q -l $ELPKG/fdoc2md.el `loads "$@"` \
28
+  --eval "(fdoc2md '$FUNC \"$TEMPF\")" > /dev/null 2>&1
29
+
30
+cat $TEMPF
31
+rm -f $TEMPF

+ 16
- 0
pkgtest.el View File

@@ -0,0 +1,16 @@
1
+;;; -*- lexical-binding: t -*-
2
+;;; pkgtest.el -- Install a test package into a clean Emacs
3
+(require 'package)
4
+
5
+(defun elpkg-test-package (tarball)
6
+  "Load the given tarball into a fake package store."
7
+  (let ((package-user-dir (concat (file-name-sans-extension tarball) ".elpa"))
8
+        (package-archives
9
+         '(("gnu"       . "http://elpa.gnu.org/packages/")
10
+           ("marmalade" . "http://marmalade-repo.org/packages/"))))
11
+    (toggle-debug-on-error)
12
+    (package-initialize)
13
+    (package-install-file tarball)
14
+    ;; TODO: check for tests and run:
15
+    ;; (ert-run-tests-batch-and-exit)
16
+    ))

Loading…
Cancel
Save