[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [eev] Dilemna
From: |
Eduardo Ochs |
Subject: |
Re: [eev] Dilemna |
Date: |
Sun, 31 Aug 2008 14:09:54 -0400 |
Hello Xavier,
I've been doing experiments myself with generating scripts
semi-automatically, but the process is still not as convenient as it
should... let me give you some examples.
If you run this,
(find-eev-update-links)
you get an "*Elisp hyperlinks*" buffer with a e-script that is part
elisp hyperlinks, part shell stuff (in eepitch blocks), and part a
multi-line (progn ...) block. So far, so good, but if you look at the
source for `find-eev-update-links', with
(find-efunction 'find-eev-update-links)
by the way: I got the sexp above by typing `M-h M-f' with the point on
"find-eev-update-links", and then doing some cut-and-paste - you will
see that definition of `find-eev-update-links' is horrible, as its
body is a big block like this:
(apply 'find-elinks `(
(find-eev-update-links ,dir ,@rest)
(find-eev-update-links "~/eev-current/" ,@rest)
(find-eev-update-links ,edir ,@rest)
...
))
I've abandoned this approach in favor of "templates" - but I just
discovered (shame!) that most of my template-based functions are still
at my .emacs... 8-( Anyway, let me give you an example of how to use
them. Here's a rewrite of find-psne-links in template-ish form:
--snip--snip--
;; First some half-mysterious, half-helpful links, as always
;; (find-find-links-links)
;; (find-find-links-links "psne")
;; (find-efunction 'find-psne-links)
;; (find-eev "eev-browse-url.el" "find-psne-links")
;; (find-eev "eev-browse-url.el" "conversion-functions" "eeurl-u-to-f")
;; (find-efunctiondescr 'ee-template)
;; (find-psne-links "{http://foo/bar}")
;; (find-psne-links "http://foo/bar")
;;
(defun find-psne-links (&optional url &rest rest)
"Visit a temporary buffer containing an e-script for psne-ing URL."
(interactive)
(apply 'find-elinks `(
;; Convention: the first sexp always regenerates the buffer.
(find-psne-links ,url ,@rest)
;; Body:
,(ee-template
`(("http://foo/bar" ,url)
("$S/http/foo/" ,(file-name-directory (eeurl-u-to-f url)))) "
(eepitch-shell)
mkdir -p {$S/http/foo/}
cd {$S/http/foo/}
wget '{http://foo/bar}'
echo '{http://foo/bar}' >> ~/.psne.log")
) rest))
(eeurl-define-from :url->action: 'find-psne-links
:remote: 'brep)
--snip--snip--
I am not sure if you are familiar with psne, brep, etc... if you put
the point over a url and type `M-x brep' the system will invoke some
tools from browse-url and will create a script to let you download a
local copy of that url...
Ok, I admit that this example is not very enlightening... but I've
been adapting this idea of templates in several ways - for example,
`M-x bruntgz' on a url like
http://www.lua.org/ftp/lua-5.1.4.tar.gz
creates a buffer whose first line is:
# (find-template-untgz "http://www.lua.org/ftp/lua-5.1.4.tar.gz" nil)
If I change it to
# (find-template-untgz "http://www.lua.org/ftp/lua-5.1.4.tar.gz" "lua")
and run that sexp, it regenerates the buffer with the right "code" for
`code-c-d', and its contents will be like this:
----snip--snip--
# (find-template-untgz "http://www.lua.org/ftp/lua-5.1.4.tar.gz" "lua")
#####
#
# lua-5.1.4
# 2008aug31
#
#####
# http://www.lua.org/ftp/lua-5.1.4.tar.gz
#
rm -Rv ~/usrc/lua-5.1.4/
tar -C ~/usrc/ -xvzf \
$S/http/www.lua.org/ftp/lua-5.1.4.tar.gz
cd ~/usrc/lua-5.1.4/
#
# (code-c-d "lua" "~/usrc/lua-5.1.4/")
# (find-luafile "")
----snip--snip--
This kind of trick has been saving me a LOT of time to write
e-scripts... I have a handful of those functions, but at this moment
most of them are debian-related, and only a few have been converted to
use ee-template, so it makes no sense to include the code for them in
this message... here's an example of their output, though
(hand-edited, of course):
http://angg.twu.net/e/coq.e.html#coq-deb-src
> As a DBA, I would (could) probably want to use it but here again
> I do not. Why ? Because even if I would use it, I would have to
> replace strings here and there to do a basic task such as
> rebuilding my indexes or stuff like that. I find it quicker and
> easier to type the query.
I am pretty sure that we can adapt these ideas to your needs as a DBA
and as a Slackware user, but how?... Can you send me some of the
scripts that you said that you always end up changing by hand? I can
try to show you how I would automate some of them and ask you for
feedback, and we may have some insights in the process...
Again: I have used databases very, very little, but let me point
(again?) to some eev features that you may not be aware of. In
http://angg.twu.net/e/sqlite.e.html#sqlite3
you will find these two defuns:
--snip--snip--
(defun eepitch-music ()
"Like `eepitch-shell', but runs \"sqlite3 /tmp/music.sqlitedb\"."
(interactive)
(eepitch-comint "sqlite: music" "sqlite3 /tmp/music.sqlitedb"))
(defun find-musicsl (sqlstatements &rest rest)
"Like `find-sh', but runs \"sqlite3 /tmp/music.sqlitedb SQLSTATEMENTS\"."
(apply 'find-eoutput-reuse
(format "*music: %s*" sqlstatements)
`(insert (find-callprocess00
'("sqlite3" "/tmp/music.sqlitedb" ,sqlstatements)))
rest))
--snip--snip--
For each database that I had - to make things simpler, let me keep
using "music" as the name of a database - I created two functions:
`eepitch-music', and `find-music<somesuffix>'... but I guess that you
know how to use these functions. What I wanted to point out is that
there are some special keys to create "eepitch headers", like:
(eepitch-music)
(eepitch-kill)
(eepitch-music)
and to wrap a single-line command - ".dump", for example - in a line
like:
-- (find-musicsl ".dump")
Some links:
(find-efunctiondescr 'ee-wrap-eepitch)
(find-eev "eev-insert.el" "ee-wrap-eepitch")
http://angg.twu.net/eev-current/eev-insert.el.html#ee-wrap-eepitch
(find-efunctiondescr 'eev-mode "wrap")
(find-efunction 'ee-hyperlink-prefix)
(find-eev "eev-insert.el" "ee-hyperlink-prefix")
http://angg.twu.net/eev-current/eev-insert.el.html#ee-hyperlink-prefix
Actually there's a key (M-S) to wrap the current line in a `find-sh',
but nothing similar for a database call; we would have to create that.
Also, I just noticed that the defuns for `eepitch-music' and
`find-musicsl', above, don't include "PAGER=cat"; `eepitch-mysql', in
my .emacs, does. Here it is:
(defun eepitch-mysql () (interactive)
(eepitch '(let ((process-environment
(cons "PAGER=cat" process-environment)))
(find-comintprocess "mysql" "mysql -u root"))))
Well, let me stop here now - and go back to the working on the
javascript version of the flipbooks
(http://angg.twu.net/emacs.html#flipbooks), and on a .texi file
generator...
Cheers,
Eduardo Ochs
address@hidden
http://angg.twu.net/
P.S.: hey - I do not expect you to digest all that that I wrote
above... au contraire! I wrote it because (1) it can be useful for
everyone reading the list, and (2) to inspire you to explain more, and
give feedback... So - your turn now? Cheers, E.
- [eev] Dilemna, Xavier Maillard, 2008/08/31
- Re: [eev] Dilemna,
Eduardo Ochs <=