]> code.delx.au - gnu-emacs-elpa/commitdiff
Merge commit '0e1d1440e4819d76cc68b213431722884af66e89'
authorrocky <rocky@gnu.org>
Wed, 25 Feb 2015 01:24:48 +0000 (20:24 -0500)
committerrocky <rocky@gnu.org>
Wed, 25 Feb 2015 01:24:48 +0000 (20:24 -0500)
1  2 
packages/load-relative/README.md
packages/load-relative/THANKS
packages/load-relative/load-relative.el
packages/load-relative/test/simple.txt
packages/load-relative/test/test-file.el

index d1d06a96687d37a988115bc8e53ebca5bdaa8bfb,563db03210bdab11d6332e2538c48072a57ff793..563db03210bdab11d6332e2538c48072a57ff793
@@@ -78,7 -78,7 +78,7 @@@ Use *require-relative-list* when you ha
  
  ## 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 +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))
+ ```
+      
index 7408d2a0352a308f692274bba31edfe82ee3e98b,f74a3efa363b036e1ccadcbccaafd43f4e71984c..f74a3efa363b036e1ccadcbccaafd43f4e71984c
--- 2/THANKS
@@@ -1,1 -1,2 +1,2 @@@
+ Phil Lord - Contribute find-file-noselect-relative, and with-relative-file
  Lars Anderson - Melapa packaging, among other things
index 16661bc32beec8eeef3a04d9d48b3d8edf7b5985,a57748a919208a86c0e183afc6f290e1c333573a..a57748a919208a86c0e183afc6f290e1c333573a
@@@ -1,7 -1,7 +1,7 @@@
  ;;; load-relative.el --- relative file load (within a multi-file Emacs package)
  
  ;; Author: Rocky Bernstein <rocky@gnu.org>
- ;; 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 +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/
  ;;
  ;;     (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:
  
@@@ -179,6 -200,32 +200,32 @@@ finding __FILE__ don't work.
        docstring interactive type))
    )
  
+ ;;;###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
index 0000000000000000000000000000000000000000,ab23474709eb118f4b7a2b0ee81244b70b3c5cc1..ab23474709eb118f4b7a2b0ee81244b70b3c5cc1
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1 +1,1 @@@
+ simple
index 0000000000000000000000000000000000000000,d2be52f6bf44e8cf3d4dbe87b7bb31dce9328aa2..d2be52f6bf44e8cf3d4dbe87b7bb31dce9328aa2
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,36 +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)))))