[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master a0983c1 14/14: Merge commit '0e1d1440e4819d76cc68b21343172
From: |
Rocky Bernstein |
Subject: |
[elpa] master a0983c1 14/14: Merge commit '0e1d1440e4819d76cc68b213431722884af66e89' |
Date: |
Wed, 25 Feb 2015 01:24:42 +0000 |
branch: master
commit a0983c1f79e5f5ce2ea01e7e47684b79c4742ea6
Merge: 1e9df93 0e1d144
Author: rocky <address@hidden>
Commit: rocky <address@hidden>
Merge commit '0e1d1440e4819d76cc68b213431722884af66e89'
---
packages/load-relative/README.md | 25 ++++++++++++-
packages/load-relative/THANKS | 1 +
packages/load-relative/load-relative.el | 57 +++++++++++++++++++++++++++---
packages/load-relative/test/simple.txt | 1 +
packages/load-relative/test/test-file.el | 36 +++++++++++++++++++
5 files changed, 114 insertions(+), 6 deletions(-)
diff --git a/packages/load-relative/README.md b/packages/load-relative/README.md
index d1d06a9..563db03 100644
--- a/packages/load-relative/README.md
+++ b/packages/load-relative/README.md
@@ -78,7 +78,7 @@ Use *require-relative-list* when you have a list of files you
want to
## provide-me
-Finally, macro *provide-me* saves you the trouble of adding a symbol
+The macro *provide-me* saves you the trouble of adding a symbol
after *provide*, by using the file basename (without directory or file
extension) as the name of the thing you want to provide. Using this
forces the *provide* names to be the same as the filename, but I
@@ -111,3 +111,26 @@ this is the same as writing:
```lisp
(provide 'bar-foo)
```
+
+
+## find-file-noselect-relative
+
+The function *find-file-noselect-relative* provides a way of accessing
+resources which are located relative to the currently running Emacs lisp file.
+This is probably most useful when running Emacs as a scripting engine for
+batch processing or with tests cases.
+
+```lisp
+ (find-file-noselect-relative "README.md")
+```
+
+## with-relative-file
+
+The macro *with-relative-file* runs in a buffer with the contents of the given
+relative file.
+
+```lisp
+ (with-relative-file "README.md"
+ (buffer-substring))
+```
+
diff --git a/packages/load-relative/THANKS b/packages/load-relative/THANKS
index 7408d2a..f74a3ef 100644
--- a/packages/load-relative/THANKS
+++ b/packages/load-relative/THANKS
@@ -1 +1,2 @@
+Phil Lord - Contribute find-file-noselect-relative, and with-relative-file
Lars Anderson - Melapa packaging, among other things
diff --git a/packages/load-relative/load-relative.el
b/packages/load-relative/load-relative.el
index 16661bc..a57748a 100644
--- a/packages/load-relative/load-relative.el
+++ b/packages/load-relative/load-relative.el
@@ -1,7 +1,7 @@
;;; load-relative.el --- relative file load (within a multi-file Emacs package)
;; Author: Rocky Bernstein <address@hidden>
-;; Version: 1.1
+;; Version: 1.2
;; Keywords: internal
;; URL: http://github.com/rocky/emacs-load-relative
;; Compatibility: GNU Emacs 23.x
@@ -30,9 +30,9 @@
;; https://github.com/rocky/emacs-load-relative/wiki/NYC-Lisp-talk for
;; the the rationale behind this.
;;
-;; The functions we add are relative versions of `load', and `require'
-;; and versions which take list arguments. We also add a `__FILE__'
-;; function and a `provide-me' macro.
+;; The functions we add are relative versions of `load', `require' and
+;; `find-file-no-select' and versions which take list arguments. We also add a
+;; `__FILE__' function and a `provide-me' macro.
;; The latest version of this code is at:
;; http://github.com/rocky/emacs-load-relative/
@@ -74,13 +74,34 @@
;;
;; (require-relative-list '("dbgr-init" "dbgr-fringe"))
;;
-;; Finally, macro `provide-me' saves you the trouble of adding a
+;; The macro `provide-me' saves you the trouble of adding a
;; symbol after `provide' using the file basename (without directory
;; or file extension) as the name of the thing you want to
;; provide.
;;
;; Using this constrains the `provide' name to be the same as
;; the filename, but I consider that a good thing.
+;;
+;; The function `find-file-noselect-relative' provides a way of accessing
+;; resources which are located relative to the currently running Emacs lisp
+;; file. This is probably most useful when running Emacs as a scripting engine
+;; for batch processing or with tests cases. For example, this form will find
+;; the README file for this package.
+;;
+;; (find-file-noselect-relative "README.md")
+;;
+;; `find-file-noselect-relative' also takes wildcards, as does it's
+;; non-relative namesake.
+;;
+;; The macro `with-relative-file' runs in a buffer with the contents of the
+;; given relative file.
+;;
+;; (with-relative-file "README.md"
+;; (buffer-substring))
+;;
+;; This is easier if you care about the contents of the file, rather than
+;; a buffer.
+
;;; Code:
@@ -180,6 +201,32 @@ finding __FILE__ don't work."
)
;;;###autoload
+(defun find-file-noselect-relative (filename &optional nowarn rawfile
wildcards)
+ "Read relative FILENAME into a buffer and return the buffer.
+If a buffer exists visiting FILENAME, return that one, but
+verify that the file has not changed since visited or saved.
+The buffer is not selected, just returned to the caller.
+Optional second arg NOWARN non-nil means suppress any warning messages.
+Optional third arg RAWFILE non-nil means the file is read literally.
+Optional fourth arg WILDCARDS non-nil means do wildcard processing
+and visit all the matching files. When wildcards are actually
+used and expanded, return a list of buffers that are visiting
+the various files."
+ (find-file-noselect (relative-expand-file-name filename)
+ nowarn rawfile wildcards))
+
+;;;###autoload
+(defmacro with-relative-file (file &rest body)
+ "Read the relative FILE into a temporary buffer and evaluate BODY
+in this buffer."
+ (declare (indent 1) (debug t))
+ `(with-temp-buffer
+ (insert-file-contents
+ (relative-expand-file-name
+ ,file))
+ ,@body))
+
+;;;###autoload
(defun load-relative (file-or-list &optional symbol)
"Load an Emacs Lisp file relative to Emacs Lisp code that is in
the process of being loaded or eval'd.
diff --git a/packages/load-relative/test/simple.txt
b/packages/load-relative/test/simple.txt
new file mode 100644
index 0000000..ab23474
--- /dev/null
+++ b/packages/load-relative/test/simple.txt
@@ -0,0 +1 @@
+simple
diff --git a/packages/load-relative/test/test-file.el
b/packages/load-relative/test/test-file.el
new file mode 100644
index 0000000..d2be52f
--- /dev/null
+++ b/packages/load-relative/test/test-file.el
@@ -0,0 +1,36 @@
+(load-file "../load-relative.el")
+(require 'ert)
+
+
+(ert-deftest test-name ()
+ (should
+ ;; not sure how I can test the full path here because, well, I need to
+ ;; resolve a relative path to do so...
+ (equal
+ "simple.txt"
+ (let ((bf
+ (find-file-noselect-relative "simple.txt")))
+ (kill-buffer bf)
+ (file-name-nondirectory
+ (buffer-file-name bf))))))
+
+(ert-deftest test-contents ()
+ (should
+ (equal
+ "simple\n"
+ (let* ((bf
+ (find-file-noselect-relative "simple.txt"))
+ (ct
+ (with-current-buffer
+ bf
+ (buffer-string))))
+ (kill-buffer bf)
+ ct))))
+
+(ert-deftest test-contents-with-relative-file ()
+ (should
+ (equal
+ "simple\n"
+ (with-relative-file
+ "simple.txt"
+ (buffer-string)))))
- [elpa] master 84151d4 02/14: Merge commit '3fa56d7925d5b24c5cd11c61bd6b3235e753a055', (continued)
- [elpa] master 84151d4 02/14: Merge commit '3fa56d7925d5b24c5cd11c61bd6b3235e753a055', Rocky Bernstein, 2015/02/24
- [elpa] master 267e9c3 04/14: New functions for opening files., Rocky Bernstein, 2015/02/24
- [elpa] master fd0e5ca 06/14: with-relative-file is now idempotent and tests!, Rocky Bernstein, 2015/02/24
- [elpa] master c72495c 08/14: Change require to path relative load., Rocky Bernstein, 2015/02/24
- [elpa] master 44980ef 07/14: Merge pull request #4 from phillord/feature/find-file-relative, Rocky Bernstein, 2015/02/24
- [elpa] master 933969e 05/14: Merge pull request #3 from phillord/feature/find-file-relative, Rocky Bernstein, 2015/02/24
- [elpa] master c0eb1f2 09/14: Commentary updates for new functions., Rocky Bernstein, 2015/02/24
- [elpa] master 8bacd50 03/14: Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs/elpa, Rocky Bernstein, 2015/02/24
- [elpa] master 4e7b211 11/14: Thank you, Phil Lord!, Rocky Bernstein, 2015/02/24
- [elpa] master 61be439 10/14: Merge pull request #5 from phillord/feature/find-file-relative, Rocky Bernstein, 2015/02/24
- [elpa] master a0983c1 14/14: Merge commit '0e1d1440e4819d76cc68b213431722884af66e89',
Rocky Bernstein <=
- [elpa] master 0e1d144 12/14: Bump version number, Rocky Bernstein, 2015/02/24
- [elpa] master 1e9df93 13/14: Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs/elpa, Rocky Bernstein, 2015/02/24