Skip to content
Browse files

load-relative.el: beef up documentation. install-from-git.sh: remove …

…test-unit, allow a GIT protocol to be specified.
  • Loading branch information...
1 parent 28aa60e commit 7de0162234628bd05b5513f811d39b07f6778e89 @rocky committed Apr 6, 2013
Showing with 151 additions and 20 deletions.
  1. +70 −6 install-from-git.sh
  2. +81 −14 load-relative.el
View
76 install-from-git.sh
@@ -1,5 +1,54 @@
#!/bin/bash
-# Install emacs-load-relative from git
+
+# This installs all realgud and its prerequisites. If you are lucky
+# you can just run this:
+#
+# bash ./install-from-git.sh
+#
+# However we do provide for some customization...
+#
+# 1. GIT PROTOCOL
+# ===============
+#
+# If your "git clone" can't handle the "http" protocol, you might be
+# able to use the "git" protocol. To do this set the GIT_PROTOCOL
+# variable like this:
+#
+# GIT_PROTOCOL=git sh ./install-from-git.sh
+#
+# 2. configure options (e.g --prefix)
+# ====================================
+
+# If you want to customize configuration parameters, for example,
+# choose where to install, you can pass configure options to this
+# script. For example:# can pass configure options.
+#
+# sh ./install-from-git.sh --prefix=/tmp
+#
+# 3. TO "sudo" or not to "sudo"?
+# ==============================
+# If you are running as root on a *Nix-like box, then there's no problem.
+#
+# If you are not running as root, "sudo" might be invoked to install
+# code. On systems that don't have a "sudo" command but need
+# filesystem permission, then you get by with setting SUDO_CMD to "su root-c"
+# For example:
+#
+# SUDO_CMD='su root -c' sh ./install-from-git.sh
+#
+# If you have sufficient filesystem permission (which is often the
+# case on Windows or cygwin) then you might not need or want sudo. So
+# here, set SUDO_CMD to a blank:
+#
+# SUDO_CMD=' ' sh ./install-from-git.sh
+#
+#
+# To finish here is an invocation using all 3 above options:
+# GIT_PROTOCOL='git' SUDO_CMD=' ' sh ./install-from-git.sh --prefix=/tmp
+
+GIT_PROTOCOL=${GIT_PROTOCOL:-http}
+
+# Run and echo a command
run_cmd() {
echo "--- Running command: $@"
$@
@@ -8,26 +57,41 @@ run_cmd() {
return $rc
}
-if (( $(id -u) != 0)) ; then
- need_sudo='sudo'
+# environment variable SUDO_CMD could be "sudo" or "su root -c" or " "
+# for don't need sudo
+
+if (( $(id -u) != 0)) ; then
+ if [[ -z "$SUDO_CMD" ]] ; then
+ need_sudo='sudo'
+ if which $need_sudo >/dev/null 2>&1 ; then
+ try_cmd=''
+ else
+ need_sudo='su root -c'
+ try_cmd='su'
+ fi
+ else
+ need_sudo="$SUDO_CMD"
+ fi
else
need_sudo=''
+ try_cmd=''
fi
+
for program in git make $need_sudo ; do
if ! which $program >/dev/null 2>&1 ; then
echo "Cant find program $program in $PATH"
exit 1
fi
done
-for pkg in emacs-{test-unit,test-simple,load-relative} ; do
+for pkg in emacs-{test-simple,load-relative} ; do
echo '******************************************'
echo Trying to install ${pkg}...
echo '******************************************'
- run_cmd git clone http://github.com/rocky/${pkg}.git
+ run_cmd git clone ${GIT_PROTOCOL}://github.com/rocky/${pkg}.git
(cd $pkg && \
run_cmd $SHELL ./autogen.sh && \
- run_cmd ./configure && \
+ run_cmd ./configure $@ && \
run_cmd make && \
run_cmd make check && \
run_cmd $need_sudo make install
View
95 load-relative.el
@@ -6,7 +6,7 @@
;; URL: http://github.com/rocky/emacs-load-relative
;; Compatibility: GNU Emacs 23.x
-;; Copyright (C) 2009, 2010, 2012 Rocky Bernstein <rocky@gnu.org>
+;; Copyright (C) 2009-2010, 2012-2013 Rocky Bernstein <rocky@gnu.org>
;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@@ -22,6 +22,73 @@
;; along with this program. If not, see
;; <http://www.gnu.org/licenses/>.
+;;; Commentary:
+
+;; Here we provide functions which facilitate writing multi-file Emacs
+;; packages and facilitate running from the source tree without
+;; having to "install" code.
+;;
+;; Te functions we add ssource out of the source relative versions of
+;; `load', and `require'. We also add a `__FILE__' and a `provide-me' macro.
+
+;; The latest version of this code is at:
+;; github.com/rocky/emacs-load-relative/
+
+;; __FILE__
+;
+;; __FILE__ returns the file name that that the calling program is
+;; running. If you are _eval_'ing a buffer then the file name of that
+;; buffer is used. The name was selected to be analogous to the name
+;; used in C, Perl, and Ruby.
+
+;; load-relative
+
+;; load-relative loads an Emacs Lisp file relative to another
+;; (presumably currently running) Emacs Lisp file. For example if you
+;; have files _foo.el_ and _bar.el_ in the same directory, then to
+;; load Emacs Lisp file _bar.el_ from inside Emacs lisp file _foo.el_:
+;;
+;; (require 'load-relative)
+;; (load-relative "baz")
+;;
+;; The above `load-relative' line could above have also been written as:
+;;
+;; (load-relative "./baz")
+;;
+;; or:
+;;
+;; (load-relative "baz.el") # if you want to exclude any byte-compiled files
+;;
+;; require-relative-list
+;;
+;; If instead of loading file "baz", you want to `require' it, do this:
+;;
+;; (require-relative "baz")
+;;
+;; or:
+;;
+;; (require-relative "./baz")
+;;
+;; The above not only does a `require_ on 'baz', but makes sure you
+;; get that from the same file as you would have if you had issued
+;; `load_relative'.
+;;
+;; If you have a list of files you want to _require_, you can require
+;; them one shot using `require-relative-list_'like this:
+;;
+;; (require-relative-list '("dbgr-init" "dbgr-fringe"))
+;;
+;; ( provide-me)
+;;
+;; Finally, 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.
+
+
(defun __FILE__ (&optional symbol)
"Return the string name of file/buffer that is currently begin executed.
@@ -51,7 +118,7 @@ methods work we will use the file-name value find via
;; suitable if __FILE__ were called from inside a function.
- (cond
+ (cond
;; lread.c's readevalloop sets (car current-load-list)
;; via macro LOADHIST_ATTACH of lisp.h. At least in Emacs
;; 23.0.91 and this code goes back to '93.
@@ -60,26 +127,26 @@ methods work we will use the file-name value find via
;; load-like things. 'relative-file-expand' tests in
;; test/test-load.el indicates we should put this ahead of
;; $#.
- (load-file-name)
+ (load-file-name)
;; Pick up "name of this file as a string" which is set on
;; reading and persists. In contrast, load-file-name is set only
;; inside eval. As such, it won't work when not in the middle of
;; loading.
- ;; (#$)
+ ;; (#$)
;; eval-like things
- ((buffer-file-name))
+ ((buffer-file-name))
;; When byte compiling. FIXME: use a more thorough precondition like
;; byte-compile-file is somehwere in the backtrace or that
- ;; bytecomp-filename comes from that routine?
+ ;; bytecomp-filename comes from that routine?
((boundp 'bytecomp-filename) bytecomp-filename)
(t (symbol-file symbol)) ;; last resort
))
-(defun autoload-relative (function-or-list
+(defun autoload-relative (function-or-list
file &optional docstring interactive type
symbol)
"autoload an Emacs Lisp file relative to Emacs Lisp code that is in
@@ -90,7 +157,7 @@ Define FUNCTION to autoload from FILE. FUNCTION is a symbol.
FILE is a string to pass to `load'.
-DOCSTRING is documentation for the function.
+DOCSTRING is documentation for the function.
INTERACATIVE if non-nil says function can be called
interactively.
@@ -108,7 +175,7 @@ finding __FILE__ don't work."
(if (listp function-or-list)
(mapcar (lambda(function)
- (autoload function-or-list
+ (autoload function-or-list
(relative-expand-file-name file symbol)
docstring interactive type))
file)
@@ -148,21 +215,21 @@ buffer-setting or buffer changing operations."
(defun require-relative (relative-file &optional opt-file opt-prefix)
"Run `require' on an Emacs Lisp file relative to the Emacs Lisp code
that is in the process of being loaded or eval'd. The symbol used in require
-is the base file name (without directory or file extension) treated as a
+is the base file name (without directory or file extension) treated as a
symbol.
WARNING: it is best to to run this function before any
buffer-setting or buffer changing operations."
- (let ((require-string-name
- (concat opt-prefix (file-name-sans-extension
+ (let ((require-string-name
+ (concat opt-prefix (file-name-sans-extension
(file-name-nondirectory relative-file)))))
- (require (intern require-string-name)
+ (require (intern require-string-name)
(relative-expand-file-name relative-file opt-file))))
(defmacro require-relative-list (list &optional opt-prefix)
"Run `require-relative' on each name in LIST which should be a list of
strings, each string being the relative name of file you want to run."
- `(progn
+ `(progn
(eval-when-compile
(require 'cl
(dolist (rel-file ,list)

0 comments on commit 7de0162

Please sign in to comment.
Something went wrong with that request. Please try again.