From 4b2cb7badb0bed8580a0eeb3b9a1f6323bc0c8ed Mon Sep 17 00:00:00 2001 From: Andreas Roehler Date: Sat, 19 Dec 2009 16:08:07 +0100 Subject: [PATCH] favourite directories implementation --- code/elbb.el | 263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- elbb.org | 3 +- 2 files changed, 259 insertions(+), 7 deletions(-) diff --git a/code/elbb.el b/code/elbb.el index a04e16f..50ab535 100644 --- a/code/elbb.el +++ b/code/elbb.el @@ -1,3 +1,260 @@ +* favourite directories implementation + +;; Author: Florent Georges, source: +;; http://fgeorges.blogspot.com/2008/01/emacs-favourite-directories.html + +;; Today, I have finally taken a look at one of the +;; simple features I always missed in Emacs: the +;; ability to define a set of "favourite directories." +;; That is, a set of named directories that one can use +;; in the minibuffer when prompted for instance to open +;; a file. Given a set of such dirs: + + ;; emacs-src -> /enter/your/path/to/emacs/sources + ;; projects -> /path/to/some/company/projects + ;; now -> @projects/the/project/I/am/working/on + +;; one can use the following path in the minibuffer to open a file, +;; for instance using C-x C-f: + + ;; @emacs-src/lisp/files.el + ;; @emacs-src/src/alloc.c + ;; @projects/great/README + ;; @now/src/some/stuff.txt + +;; Doing so, completion is available for both directory names and +;; files under their target directories. For instance, to open the +;; third file above, you only have to type: + + ;; C-x C-f @ p g R + +;; The implementation I have just written is really simple, but +;; useful yet. It implements all described above (including +;; recursive defined directories, as the '@now' above.) Thanks to +;; Emacs, I am still suprised by the facility to implement such a +;; feature! + +;; The code was written on GNU Emacs 22.1 on Windows, but should +;; work on any platform, and I think on Emacs 21 as well. + +;; TODO: Make a custom variable. +(defvar drkm-fav:favourite-directories-alist + '(("saxon-src" . "y:/Saxon/saxon-resources9-0-0-1/source/net/sf/saxon") + ("kernow-src" . "~/xslt/kernow/svn-2007-09-29/kernow/trunk/src/net/sf/kernow")) + "See `drkm-fav:handler'.") + +(defvar drkm-fav::fav-dirs-re + ;; TODO: Is tehre really no other way (than mapcar) to get the list + ;; of the keys of an alist?!? + (concat + "^@" + (regexp-opt + (mapcar 'car drkm-fav:favourite-directories-alist) + t)) + "Internal variable that stores a regex computed from +`drkm-fav:favourite-directories-alist'. WARNING: This is not +updated automatically if the later variable is changed.") + +(defun drkm-fav:handler (primitive &rest args) + "Magic handler for favourite directories. + +With this handler installed into `file-name-handler-alist', it is +possible to use shortcuts for often used directories. It uses +the mapping in the alist `drkm-fav:favourite-directories-alist'. + +Once installed, say you have the following alist in the mapping +variable: + + ((\"dir-1\" . \"~/some/real/dir\") + (\"dir-2\" . \"c:/other/dir/for/windows/users\")) + +You can now use \"@dir-1\" while opening a file with C-x C-f for +instance, with completion for the abbreviation names themselves +as well as for files under the target directory." + (cond + ;; expand-file-name + ((and (eq primitive 'expand-file-name) + (string-match drkm-fav::fav-dirs-re (car args))) + (replace-match + (cdr (assoc (match-string 1 (car args)) + drkm-fav:favourite-directories-alist)) + t t (car args))) + ;; file-name-completion + ((and (eq primitive 'file-name-completion) + (string-match "^@\\([^/]*\\)$" (car args))) + (let ((compl (try-completion + (match-string 1 (car args)) + drkm-fav:favourite-directories-alist))) + (cond ((eq t compl) + (concat "@" (match-string 1 (car args)) "/")) + ((not compl) + nil) + (t + (concat "@" compl))))) + ;; file-name-all-completions + ((and (eq primitive 'file-name-all-completions) + (string-match "^@\\([^/]*\\)$" (car args))) + (all-completions + (match-string 1 (car args)) + drkm-fav:favourite-directories-alist)) + ;; Handle any primitive we don't know about (from the info node + ;; (info "(elisp)Magic File Names")). + (t (let ((inhibit-file-name-handlers + (cons 'drkm-fav:handler + (and (eq inhibit-file-name-operation primitive) + inhibit-file-name-handlers))) + (inhibit-file-name-operation primitive)) + (apply primitive args))))) + +;; Actually plug the feature into Emacs. +(push '("\\`@" . drkm-fav:handler) file-name-handler-alist) + +* lisp interface to ispell + +;; From: Teemu Likonen +;; Date: Fri, 06 Nov 2009 22:05:53 +0200 +;; To: help-gnu-emacs@gnu.org +;; Subject: Re: lisp interface to ispell ? + +;; On 2009-11-06 20:39 (+0100), Andreas Politz wrote: + +;; > Does someone have a hack, or know a different package, in order to allow +;; > elisp access to spelling functions ? E.g. like +;; > +;; > (spell word language) +;; > +;; > which at least returns t or nil. + +;; Something like this? + +(defun my-ispell-string (word lang) + (with-temp-buffer + (insert word) + (call-process-region (point-min) (point-max) + "ispell" t t nil "-l" "-d" lang) + (if (= (point-min) (point-max)) + t))) + +* Python workflow + +;; From: Simon +;; Date: Fri, 6 Nov 2009 03:42:44 -0800 (PST) +;; To: help-gnu-emacs@gnu.org +;; Subject: Python workflow + +;; Hi, apologies in advance for a potentially numpty post. + +;; I've been using Emacs for a little while now, but I've yet to settle +;; on a satisfactory python edit-run-debug cycle, and I was wondering +;; what wiser minds than mine have settled upon. So far I've tried: + +;; - Edit code and run with emacs PDB. After fiddling the lisp code to +;; automatically pick up the current buffer as the default run candidate, +;; this is nearly okay. The main issue is that, after editing code, +;; there's no easy way to rerun the code, so I end up killing the gud +;; buffer every time. As such, entering and leaving the debugger is quite +;; a few key presses and accidentally leaving it running is also easy. + +;; - Tried Pydb to similar effect. + +;; - Run everything in a seperate shell. And debug by hand. This is a +;; little too low-fi, even for me. + +;; - Use the 'import/reload file' and 'eval def/class' functions, and run +;; everything from the emacs python shell, using pdbtrack to help with +;; debugging. Problems so far: +;; - It's very easy to forget which modules you've modified and fail to +;; reload them; because the state is carried over I continually find +;; myself running the old versions of code I've just edited, especially +;; if it's across several files. +;; - More than that, sometimes the stuff I expect to reload simply +;; doesn't, and I have no indication as to why. For example, if pdb has +;; module open and you stick a deliberate error in the code and reload +;; it, the minibuffer tells you the module has been loaded, even though +;; it clearly can't have been. +;; - I have to run pdb.pm() to debug the exception. If I run *anything* +;; else by accident, I lose the exception context. This can be annoying +;; if you're incompetent enough to keep making typos (I am). + +;; Does anyone have any tips on their workflow? + +;; Many thanks! + +;; Simon + +* strip out UTF-8 BOMs +;; From: "Edward O'Connor" +;; Date: Thu, 5 Nov 2009 16:13:27 -0800 +;; To: emacs-devel@gnu.org +;; Subject: find-file-literally-at-point +;; +;; Hi, +;; +;; I recently found myself in need of such a function (I was going through +;; a bunch of files to strip out their UTF-8 BOMs, if you're curious), and +;; it was quick enough to put together: + +(autoload 'ffap-guesser "ffap") +(defun find-file-literally-at-point () + "Open the file at point (like `ffap') with `find-file-literally'." + (interactive) + (find-file-literally (ffap-guesser))) + +* xml and n3 + +;; From: "Eric Schulte" +;; Subject: Re: [Orgmode] org-babel-tangle xml text +;; Date: Tue, 03 Nov 2009 09:18:34 -0700 + +;; "Martin G. Skjæveland" writes: + +;; > Is there a way I can add xml and n3 to the list of supported +;; > languages? These languages does not need interpretation, so I'm +;; > thinking it should be quite easy to add. I have fumblingly tried +;; > +;; > (add-to-list 'org-babel-tangle-langs '("xml")) +;; > +;; > and +;; > +;; > (add-to-list 'org-babel-tangle-langs '("css" "xml")) +;; > +;; > but it as no effect. +;; > + +;; Hi Martin, + +;; The attached org-mode file contains instructions for adding xml and n3 +;; to org-babel and org-babel-tangle. Note that there may be another step +;; if the major mode for n3 is not n3-mode. Best -- Eric + +;; introduce org-babel to =xml= and =n3= + +#+begin_src emacs-lisp :results silent + (org-babel-add-interpreter "xml") + (org-babel-add-interpreter "n3") +#+end_src + +;; if say =n3= should be edited using =xml-mode=, then evaluate the +;; following adding this pair to =org-src-lang-modes= +#+begin_src emacs-lisp :results silent + (add-to-list 'org-src-lang-modes '("n3" . xml)) +#+end_src + +;; inform org-babel-tangle of their existence and file extensions +#+begin_src emacs-lisp :results silent + (add-to-list 'org-babel-tangle-langs '("xml" "xml" nil t)) + (add-to-list 'org-babel-tangle-langs '("n3" "n3" nil t)) +#+end_src + +#+begin_src xml :tangle example + + +#+end_src + +#+begin_src n3 :tangle example + n3 stuff +#+end_src + ;; * How to check regexp for syntax-errors? ;; From: Kevin Rodgers @@ -56,8 +313,6 @@ ;; -- ;; David Kastrup - - ;; * batch-mode ;; From: Decebal @@ -102,7 +357,6 @@ ;; To: help-gnu-emacs@gnu.org ;; Envelope-To: andreas.roehler@easy-emacs.de - ;; On Sat, 10 Oct 2009 11:33:17 -0700 (PDT), Decebal said: ;; > ... ;; > local i @@ -120,7 +374,6 @@ ;; ---Vassil. - ;; From: Decebal ;; Newsgroups: gnu.emacs.help ;; Date: Sat, 10 Oct 2009 13:57:07 -0700 (PDT) @@ -149,7 +402,6 @@ ;; But maybe there should be more consideration for the possibility that ;; Emacs is used as a batch program. - ;; > > Wrote /home/cecil/temp/inputEmacs ;; I still have to find something for this. @@ -157,7 +409,6 @@ ;; That is not possible I am afraid. In the C-source there is a call to ;; message_with_string. - ;; * vectors and lists ;; From: pjb@informatimago.com (Pascal J. Bourguignon) diff --git a/elbb.org b/elbb.org index 0ba191c..0ac20b4 100644 --- a/elbb.org +++ b/elbb.org @@ -5,7 +5,7 @@ #+LANGUAGE: en #+OPTIONS: skip:nil toc:nil * How to check regexp for syntax-errors? -#+BEGIN_SRC emacs-lisp + ;; From: Kevin Rodgers ;; Date: Tue, 20 Oct 2009 01:54:56 -0600 ;; Subject: Re: How to check regexp for syntax-errors? (There HAS to be SOME @@ -14,6 +14,7 @@ ;; > Isn't there some .el that that will try to parse a regexp, and tell ;; > me where it got confused, and what to look for for errors? +#+BEGIN_SRC emacs-lisp (defun valid-regexp-p (regexp) (interactive "sRegexp: ") (with-temp-buffer -- 2.11.4.GIT