search-whitespace-regexp
[elbb.git] / code / elbb.el
blob44e8161f2c9705860f74d09dec3b7824813e0435
1 * search-whitespace-regexp
3 To: help-gnu-emacs@gnu.org
4 From: Daniel Pittman <daniel@rimspace.net>
5 Date: Sat, 03 Jul 2010 23:14:59 +1000
6 Subject: Re: Why does this happen in regexp isearch?
8 Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:
10 > I open cus-edit.el.gz in Emacs and do a regexp isearch for:
12 > ^ ;;
14 > (Beginning of line, then two spaces, then two semicolons.)
16 > For some reason that I don't understand, it seems to match "beginning
17 > of line, any number of spaces OR tabs, then two semicolons". When I
18 > search for:
20 > ^ \{2\};;
22 > ...it finds what I'm looking for. Why is this?
24 (defcustom search-whitespace-regexp (purecopy "\\s-+")
25 "If non-nil, regular expression to match a sequence of whitespace chars.
26 This applies to regular expression incremental search.
27 When you put a space or spaces in the incremental regexp, it stands for
28 this, unless it is inside of a regexp construct such as [...] or *, + or ?.
29 You might want to use something like \"[ \\t\\r\\n]+\" instead.
30 In the Customization buffer, that is `[' followed by a space,
31 a tab, a carriage return (control-M), a newline, and `]+'.
33 When this is nil, each space you type matches literally, against one space."
34 :type '(choice (const :tag "Find Spaces Literally" nil)
35 regexp)
36 :group 'isearch)
38 Regards,
39 Daniel
40 --
41 ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
42 ♽ made with 100 percent post-consumer electrons
44 * tabs instead of spaces in C mode
46 Date: Sun, 2 May 2010 22:13:04 -0400
47 From: Steve Revilak <steve@srevilak.net>
48 To: help-gnu-emacs@gnu.org
49 Subject: Re: Emacs behavior
51 >From: "VICTOR TARABOLA CORTIANO"=20
53 >I would like to change the default behavior of Emacs in C mode, I
54 >use tabs instead of spaces for editing, so I changed my .emacs[1]
55 >to behave the way I want.
57 >For instance, I want:
59 >function()
61 > commands;
64 >But Emacs automatically modify the text to:
66 >function()
67 > {
68 > commands;
69 > }
71 >It works the way I want in text-mode, but I want syntax highligting.
73 >I would like Emacs to behave like mg or vi in C mode.
75 I've been working on a C project where most of the source code was
76 indented using tabs, and I wanted my edits to follow the same
77 formatting. A solution that worked for me was
80 * Local Variables:
81 * c-basic-offset: 8
82 * indent-tabs-mode: t
83 * End:
86 I added this Local Variables block at the bottom of each .c file I
87 needed to edit. (I didn't want to change the behavior of C mode
88 globally; instead, I merely wanted to change it in a few specific
89 files.)
91 Putting something like
93 (setq c-basic-offset 8
94 indent-tabs-mode t)
96 into ~/.emacs may give some of the behavior you're looking for.
98 You can also try
100 (setq c-indentation-style "linux")
102 For a description of cc-mode styles, these are good places to start:
104 http://www.gnu.org/software/emacs/manual/html_node/ccmode/Choosing-a-Sty=
105 le.html#Choosing-a-Style
106 http://www.gnu.org/software/emacs/manual/html_node/ccmode/Built_002din-S=
107 tyles.html#Built_002din-Styles
109 Finally, c-insert-tab-function might also be useful to you.
111 http://www.gnu.org/software/emacs/manual/html_node/ccmode/Indentation-C=
112 ommands.html#index-TAB-17
114 Steve
116 * Using Git to manage your Emacs changes
118 To: emacs-devel@gnu.org
119 From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
120 Date: Fri, 09 Apr 2010 08:04:16 +0200
121 Subject: Re: Using Git to manage your Emacs changes
123 John Wiegley <jwiegley@gmail.com> writes:
125 > On Apr 7, 2010, at 4:37 PM, Thierry Volpiatto wrote:
127 >> Why not using a stack of patchs like stgit or mercurial qpatchs.
128 >> You can then apply these patchs to bzr repo.
130 > I don't see how stgit improves anything. Also, I'm using git-bzr
131 > because I need to fetch the mirrored commits back into Git immediately
132 > after pushing, and I'm not sure how often the GitHub emacs mirror
133 > updates itself.
135 I use http://repo.or.cz/w/emacs.git
137 This repo is converted to a hg repo locally.
138 I have cloned this hg repo to another hg repo that handle qpatchs.
139 So i have three repos:
141 git, hg, hg qpatch.
143 1) on git repo: git pull
145 2) on hg repo: hg convert <last git revision>
146 (when the repo exists, hg convert is as fast as a pull)
148 3) on hg qpatch repo: hg pull
150 4) make some new patchs on hg qpatch repo (i use DVC and
151 anything-mercurial.el)
153 5) Then you can send patchs to Emacs or apply these patchs to bzr repo
154 directly.(your patchs have to be in git format)
156 The same can be done with stg.(with only 2 repo)
159 Thierry Volpiatto
160 Gpg key: http://pgp.mit.edu/
162 * Guile in Emacs (was: integer overflow)
164 From: Thomas Lord <lord@emf.net>
165 To: rms@gnu.org
166 Date: Sun, 11 Apr 2010 16:33:57 -0700
167 Subject: Re: Guile in Emacs (was: integer overflow)
169 I'd like to correct some accounts of history.
171 On Mon, 2010-03-08 at 22:19 -0500, Richard Stallman wrote:
172 > RS> If it only supports something like Emacs Lisp then it is not much of
173 > RS> an advance. Guile supports Scheme and Javascript as well as Emacs Lisp.
175 > It also supports multithreading, which IMHO is a big deal as well,
176 > perhaps more important than bignums.
178 > I think the support for multiple languages is the biggest advance.
179 > I hope support for other popular extension languages will be
180 > implemented
181 > eventually -- that was the original goal of Guile.
183 Your recollection there seems to me to be mistaken. It
184 was a long time ago but I distinctly remember things
185 differently. As I recall:
187 The original GNU Manifesto described a unix-like foundation
188 with a heavy emphasis on a Lisp-centric user-space.
190 In the early 1990s, when I worked at the FSF, several
191 of the hackers there (including me) understood the GNU
192 vision to imply that many interactive programs - not just
193 Emacs - would be extensible in a dialect of Lisp. We
194 mostly shared the opinion that Scheme was an appropriate
195 dialect.
197 Before I got to the FSF people had already started on a
198 GNU Extension Language Library - an embeddable Scheme
199 interpreter. As the (bad) "joke" goes: they code-named the
200 project "revoc" but upon reflection that's just a "cover".
201 (Get it? Spooky, ain't it?)
203 Revoc was (at least back then) going nowhere fast. Later,
204 while working on a spreadsheet program, I attempted to start
205 a new attempt at a scheme-based extension language library.
206 You were (rightly, I suppose) upset that there were higher
207 priorities. You also pointed out that I was probably wasting
208 time by starting from scratch and that I ought to have started
209 from some existing Scheme implementation. I don't recall
210 if you specifically suggested SCM but I think you might have.
211 So there were two attempts at a Scheme-based GNU extension
212 library down - and one to go.
214 A year or two later I went to work for Cygnus and we, there,
215 initially agreed to invest in making a scheme-based extension
216 language library for GNU programs. This was originally named
217 "GEL" (for GNU Extension Language) until the company lawyers
218 warned that "GEL" was a trademark for another program. It
219 was renamed Guile (a cognitive relative of "scheme" and a
220 pun for "Guy L."). You were informed of this work and were
221 encouraging. I forget at which stage of this process you
222 declared Guile to be a "GNU project" but I'm sure the extant
223 public record has it somewhere.
225 Around that time, Sun was beginning to announce and promote
226 Java. They also hired John Ousterhout and began declaring
227 "Tcl is to be the scripting language for the Internet!" Back
228 then, Sun was a particularly influential company. On a
229 technical level, Tcl was a horribly regressive language -
230 a giant step backwards in many subtle but important ways.
231 Its license was a free software license but it was uncomforable
232 at the time to have Sun pushing it so heavily because of
233 the technical problems and because of doubts about Sun's
234 motives and control over the software.
236 A faction arose within Cygnus that argued that Cygnus should
237 divest from the Guile project and adopt Tcl instead. I made
238 you aware of that and of Sun's swagger, regarding Tcl.
240 Around the same time, two of Prof. Ousterhout's graduate
241 students, John Blow and Adam Sah, were proposing that
242 the TCL language be *altered* in some small but significant
243 ways that would facilitate its translation into reasonable
244 efficient Scheme code. Their altered version of Tcl was
245 largely but not completely upward compatible with standard
246 Tcl. By applying a Scheme->C compiler to the generated
247 Scheme code, they were able to benchmark far better than
248 standard Tcl in many cases.
250 And around that same time I was independently proposing
251 similar things. Mssrs. Blow, Sah, and I compared notes
252 and so forth.
254 Around that time, also, Python was beginning to gain
255 recognition in the US (it already had a foothold in Europe).
256 Blow, Sah, and I had dinner with Von Rossum and tried to
257 persuade him to add LAMBDA and proper tail calls and perhaps
258 continuations to the language so that it could be usefully
259 translated to Scheme. He did not agree. Back at Cygnus,
260 the oppositional factions had fun lampooning lisp syntax
261 and pointing to examples like Python of what was better.
263 Some of my notes to you mysteriously transmogrified into
264 a USENET post which the archives show as having you in the
265 "From:" line and with my signature at the bottom of the
266 message. This sparked what people, to this day,
267 still call "The TCL war".
271 The "original goal" of Guile was most definitely *not*
272 to support multiple languages. Rather, that was a goal
273 that was established as a tactic in response to early
274 competition with Guile.
276 Moreover, it was *never*, in the early days, a goal
277 that Guile support other popular extension languages.
278 That was something that you added and that I (regrettably)
279 agreed to in response to the perceived threat of Tcl
280 and to a lesser extent Python.
282 And: it was *never* in those years a goal to support
283 any of those other languages exactly. It was *always*
284 a goal to have a Tcl-like syntax, a Python-like syntax,
285 and a C-like syntax for Guile Scheme. But tight
286 compatibility with those languages was *not* the goal.
287 The notion wasn't so much to "support Tcl" (or any other
288 language) as to have a hyper-flexible syntax and to
289 support, via libraries, environments with all of the
290 convenience features of a shell-like language like Tcl.
292 Early on after we adopted that tactic you and I and
293 a few others had some lengthy discussions about adding
294 Emacs Lisp to the list of languages that Guile could
295 run. We ran into some severe issues such as the
296 difference between 'NIL in Emacs lisp and '() and Scheme.
297 Perhaps not to you but to several other of us it became
298 fairly clear, back then, that a strictly compatible
299 Emacs lisp would never sit comfortably alongside a
300 proper Scheme environment. Just as we would need to make
301 a "Tcl-like" language that would break some Tcl code,
302 we would need to break some Emacs lisp code, if indeed
303 we ultimately wanted to bother trying to support any.
304 (That is part of why, at Cygnus, I built a from-scratch
305 multi-buffer, self-documenting, extensible text editor
306 in Scheme with multi-font and proportionally-spaced
307 font capabilities that, at the time, GNU Emacs wasn't
308 close to achieving. The notion was to see how far I could
309 get just leapfrogging over GNU Emacs instead of trying
310 to retrofit it.)
312 Now, years have passed. In recent years, I gather,
313 the implementation of Guile has been fairly radically
314 altered so that it is now more of a bytecode VM with
315 primitive LISP-ish types. In some sense, it has begun
316 to drift away from being primarily a Scheme to being
317 more in the category of JVM or the Mono VM. It is easier
318 to target multiple languages to such a VM but no less
319 easy to make them interoperate cleanly in a way one would
320 want to live with for the long run.
322 So Guile's goals have shifted. It was once (originally)
323 to be a tight, clean, fun Scheme environment with some
324 alternative syntaxes and specialized environments -- and
325 only later did it become the kind of heterogenous language
326 environment we see it moving towards today.
328 So, again:
330 > I hope support for other popular extension languages will be
331 > implemented eventually -- that was the original goal of Guile.
333 Nah. The heck it was. That's just not true.
335 Now, there is a separate question: is that goal to support
336 other popular extension languages a better idea or a worse
337 idea (or not importantly different) than the original goal
338 of a nice, tight, fun Scheme-based system?
340 I have my opinion ("far worse!") but it's not my intent
341 to argue for that opinion here. Just to set history straight.
343 That multi-lingual stuff was *not* the original goal of Guile.
344 On the contrary, the multi-lingual goals only came up at all
345 because of a perceived crisis sparked by Sun's announcement
346 that Tcl was to become the ubiquitous scripting language of
347 the Internet.
351 * emacs daemon.. but quietly
353 To: help-gnu-emacs@gnu.org
354 From: Richard Riley <rileyrgdev@gmail.com>
355 Date: Mon, 22 Mar 2010 20:02:22 +0100
356 Subject: Re: emacs daemon.. but quietly
358 tomas@tuxteam.de writes:
360 > On Fri, Mar 05, 2010 at 02:24:44PM +0100, Gary . wrote:
361 >> Is there any way to stop emacs, run with --daemon, printing out
362 >> details about all of the config files it is loading? At the moment I
363 >> see
365 > If I understand you correctly, you want to suppress stdout/stderr output
366 > of emacs --daemon?
368 > You might just redirect that to /dev/null like so:
370 > emacs --daemon > /dev/null 2>&1
372 > (or did I misunderstand you completely?)
374 >> ("emacs" "--quiet")
375 >> Loading charset...
376 >> Loading charset...done
377 >> (etc.) which is ugly since I want to start the server, when
378 >> appropriate, when I start my login shell by doing something like
380 >> function serverExists {
381 >> TMPDIR=${TMPDIR-/tmp};
382 >> TMPFILE="${TMPDIR}/ps-output.$$";
384 >> ps > ${TMPFILE}
385 >> grep -q 'emacs-X11' ${TMPFILE}
386 >> SERVER_STARTED=$?;
387 >> rm ${TMPFILE}
389 >> return $SERVER_STARTED;
390 >> }
392 >> if serverExists ; then
393 >> export EMACS_SERVER="emacs already started"
394 >> else
395 >> emacs --daemon --quiet
396 >> export EMACS_SERVER="emacs started here"
397 >> fi
398 >> echo $EMACS_SERVER
400 >> in my .bashrc.
402 > Hm. I don't quite understand this part. Besides, it seems a roundabout
403 > way. What are you trying to achieve?
405 > Regards
406 > -- tomás
409 As is emacs --daemon IMO.
411 In emacs 23 using the alternate editor setting. My "edit" script is:-
413 ,----
414 | #!/bin/bash
415 | # edit
416 | export GDK_NATIVE_WINDOWS=1
417 | exec emacsclient --alternate-editor="" -c "$@"
418 `----
420 Its in the man page for emacsclient and the wiki.
423 ASCII ribbon campaign ( )
424 - against HTML email X
425 & vCards / \
427 * Reading a sequence of bytes as one integer
429 Date: Sat, 13 Mar 2010 20:49:28 +0200
430 From: Eli Zaretskii <eliz@gnu.org>
431 To: help-gnu-emacs@gnu.org
432 Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer
434 > Date: Sat, 13 Mar 2010 11:56:17 -0500 (EST)
435 > From: Jeff Clough <jeff@chaosphere.com>
437 > I have a (mostly) binary file I want to inspect. There are several
438 > places in this file where I want to read a series of bytes (in this
439 > case, three consecutive bytes) and treat those bytes as a single
440 > integer. I can grab them as a buffer-substring obviously, but I'm at
441 > a loss for how to make that into the integer I need, nor can I find
442 > anything obvious that would be easier.
444 Take a look at bindat.el (it's bundled with Emacs).
446 * how to access a large datastructure efficiently?
448 To: help-gnu-emacs@gnu.org
449 From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
450 Date: Thu, 04 Mar 2010 17:09:35 +0100
451 Subject: Re: how to access a large datastructure efficiently?
453 Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
455 > Thierry Volpiatto wrote:
456 >> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
458 >>> Thierry Volpiatto wrote:
459 >>>> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
460 >>>>
461 >>>>> Hi,
462 >>>>>
463 >>>>> Christian Wittern <cwittern@gmail.com> writes:
464 >>>>>
465 >>>>>> Hi there,
466 >>>>>>
467 >>>>>> Here is the problem I am trying to solve:
468 >>>>>>
469 >>>>>> I have a large list of items which I want to access. The items are in
470 >>>>>> sequential order, but many are missing in between, like:
471 >>>>>>
472 >>>>>> (1 8 17 23 25 34 45 47 50) [in reality, there is a value associated
473 >>>>>> with this, but I took it out for simplicity]
474 >>>>>>
475 >>>>>> Now when I am trying to access with a key that is not in the list, I
476 >>>>>> want to have the one with the closest smaller key returned, so for 6
477 >>>>>> and 7 this would be 1, but for 8 and 9 this would be 8.
478 >>>>>>
479 >>>>>> Since the list will have thousands of elements, I do not want to simply
480 >>>>>> loop through it but am looking for better ways to do this in Emacs lisp.
481 >>>>>> Any ideas how to achieve this?
482 >>>>> ,----
483 >>>>> | (defun closest-elm-in-seq (n seq)
484 >>>>> | (let ((pair (loop with elm = n with last-elm
485 >>>>> | for i in seq
486 >>>>> | if (and last-elm (< last-elm elm) (> i elm)) return (list last-elm i)
487 >>>>> | do (setq last-elm i))))
488 >>>>> | (if (< (- n (car pair)) (- (cadr pair) n))
489 >>>>> | (car pair) (cadr pair))))
490 >>>>> `----
491 >>>>>
492 >>>>> That return the closest, but not the smaller closest, but it should be
493 >>>>> easy to adapt.
494 >>>> Case where your element is member of list, return it:
495 >>>>
496 >>>> ,----
497 >>>> | (defun closest-elm-in-seq (n seq)
498 >>>> | (let ((pair (loop with elm = n with last-elm
499 >>>> | for i in seq
500 >>>> | if (eq i elm) return (list i)
501 >>>> | else if (and last-elm (< last-elm elm) (> i elm)) return (list last-elm i)
502 >>>> | do (setq last-elm i))))
503 >>>> | (if (> (length pair) 1)
504 >>>> | (if (< (- n (car pair)) (- (cadr pair) n))
505 >>>> | (car pair) (cadr pair))
506 >>>> | (car pair))))
507 >>>> `----
508 >>>> For the smallest just return the car...
509 >>>>
510 >>> if n is member of the seq, maybe equal-operator too
512 >>> (<= last-elm elm)
514 >>> is correct?
516 >> No, in this case:
518 >> if (eq i elm) return (list i) ==> (i) ; which is n
520 >> and finally (car pair) ==> n
523 > Hmm, sorry being the imprecise,
524 > aimed at the first form, whose result equals the the second form once implemented this "="
526 Ok, i understand, yes, we can do what you say and it's more elegant, i
527 just notice also i forget to remove a unuseful else:
529 ,----
530 | (defun closest-elm-in-seq (n seq)
531 | (let ((pair (loop with elm = n with last-elm
532 | for i in seq
533 | if (and last-elm (<= last-elm elm) (> i elm)) return (list last-elm i)
534 | do (setq last-elm i))))
535 | (if (< (- n (car pair)) (- (cadr pair) n))
536 | (car pair) (cadr pair))))
537 `----
539 That should work the same.
540 Thanks. ;-)
543 Thierry Volpiatto
544 Gpg key: http://pgp.mit.edu/
546 To: help-gnu-emacs@gnu.org
547 From: Andreas Politz <politza@fh-trier.de>
548 Date: Thu, 04 Mar 2010 17:49:54 +0100
549 Subject: Re: how to access a large datastructure efficiently?
551 [ ... ]
553 I don't know how hash-table could help in this case, but maybe you want
554 to consider binary trees, as implemented in the avl-tree.el package.
555 Though, there is no function for finding the closest member with respect
556 to some data and a distance-function, but see below.
558 Finding a (closest) member should be constraint in logarithmic time.
560 (require 'avl-tree)
562 (setq avl (avl-tree-create '<))
564 (dotimes (i 2000)
565 (when (= 0 (% i 4))
566 (avl-tree-enter avl i)))
568 (avl-tree-member avl 80)
569 => 80
570 (avl-tree-member avl 70)
571 => nil
573 (defun avl-tree-closest-member (tree data delta-fn)
574 ;; delta-fn : data x data -> Z
575 (flet ((comp-delta (node)
576 (funcall delta-fn data
577 (avl-tree--node-data node))))
578 (let* ((node (avl-tree--root tree))
579 closest
580 (delta most-positive-fixnum)
581 (compare-function (avl-tree--cmpfun tree))
582 found)
583 (while (and node
584 (not found))
585 (when (< (comp-delta node) delta)
586 (setq delta (comp-delta node)
587 closest node))
588 (cond
589 ((funcall compare-function data (avl-tree--node-data node))
590 (setq node (avl-tree--node-left node)))
591 ((funcall compare-function (avl-tree--node-data node) data)
592 (setq node (avl-tree--node-right node)))
594 (setq found t))))
595 (if closest
596 (avl-tree--node-data closest)
597 nil))))
599 (mapcar
600 (lambda (data)
601 (avl-tree-closest-member
602 avl data (lambda (n1 n2)
603 (abs (- n1 n2)))))
604 '(1001 1002 1003 1004))
606 => (1000 1004 1004 1004)
610 * cedet and auto-complete
612 To: help-gnu-emacs@gnu.org
613 From: Richard Riley <rileyrgdev@gmail.com>
614 Date: Tue, 02 Mar 2010 08:26:20 +0100
615 Subject: Re: cedet and auto-complete
617 Richard Riley <rileyrgdev@gmail.com> writes:
619 > Just another quick poll to see if anyone has got the new cedet working
620 > with auto-complete. cedet has developed its own completion UIs but
621 > ideally I would like to use auto-complete as I do in all other
622 > modes. Has anyone a workaround or instructions for allowing this to
623 > work? Unfortunately if you only enable the minimum features which then
624 > turns off the cedet completion mechs, it also turns off the semantic
625 > navigation features which kind of detracts from its usefulness.
627 > Any help or pointer appreciated,
629 > r.
632 OK, user errror to a degree - I have now moved back to company-mode
633 (newer version is available) and made sure it was on the load path
634 before the version that came with nxhtml.
636 Works well.
638 Here is my simple setup which turns on ispell support in text-mode and
639 so works in gnus message modes.
641 (add-to-list 'load-path "~/.emacs.d/company-mode")
642 (require 'company)
643 (add-hook 'text-mode-hook (lambda()(add-to-list 'company-backends 'company-ispell)))
644 (require 'company-ispell)
645 (global-company-mode)
647 This is with cedet 1.0pre7 and company-mode 0.5
649 * hide-show squash-minor-modes
651 From: Thien-Thi Nguyen <ttn@gnuvola.org>
652 To: Andreas Roehler <andreas.roehler@online.de>
653 Subject: Re: hideshow condensed view
654 Date: Thu, 25 Feb 2010 16:21:27 +0100
656 () Andreas Roehler <andreas.roehler@online.de>
657 () Thu, 25 Feb 2010 15:24:24 +0100
659 thanks a lot maintaining hideshow.el.
661 In the last few years, i can't take any credit for its improvement.
662 See Emacs' ChangeLog for those who actually merit the appreciation...
664 Use it as default outline-mode now.
666 Cool.
668 Just one thing remains so far: hs displays an empty
669 line between headers. Would prefer a more condensed
670 view.
672 You must have good eyes (still); i use hideshow not
673 for density but for spaciousness.
675 Might it be possible to introduce a function
676 `hide-all-empty-lines', inclusive a variable which may
677 be customized?
679 Yeah, it would be possible, but i tend to think of empty lines outside
680 the (top-level) blocks as also outside the scope of hideshow. It's like
681 in the book GEB, there is the tree and there is the stuff outside the
682 tree. Get it?
684 I am already troubled by hideshow straying from its conceptual (both
685 meanings) simplicity -- a block is between matching parens, no more no
686 less -- but that's just me...
688 All this is to say, you probably should write a "squash minor mode",
689 which puts the invisible property on an overlay for text that matches
690 the empty line regexp (which of course, could be made customizable), at
691 which point my advice would be to add a hook to `hs-hide-all' to enable
692 this mode.
694 Here's a quick (but tested (lightly)) sketch:
696 (defvar empty-lines-rx "^\\s-*\\(\n\\s-*\\)+")
698 (defvar empty-lines nil
699 "List of empty lines (overlays).")
701 (defvar squash-minor-mode nil)
703 (defun squash-minor-mode ()
704 (interactive)
705 (setq squash-minor-mode (not squash-minor-mode))
706 (if squash-minor-mode
707 (save-excursion
708 (goto-char (point-min))
709 (while (re-search-forward empty-lines-rx nil t)
710 (let ((ov (make-overlay (match-beginning 0) (match-end 0))))
711 (overlay-put ov 'display "")
712 (push ov empty-lines))))
713 (mapc 'delete-overlay empty-lines)
714 (setq empty-lines nil))
715 (message "empty-lines squashing %s" (if squash-minor-mode 'on 'off)))
717 Have fun!
721 * questioning let
723 Andreas Roehler <andreas.roehler@online.de> writes:
725 > Hi,
727 > behaviour of the example code below puzzles me. Would
728 > expect setting of arg by external function, but inside
729 > `let', recognised. But remains `1'.
731 > (defun arg-setting ()
732 > (interactive)
733 > (let ((arg 1))
734 > (message "%s" arg)
735 > (arg-extern arg)
736 > (message "%s" arg)))
738 > (defun arg-extern (arg)
739 > (setq arg (1- arg)))
741 > Any help?
743 From: David Kastrup <dak@gnu.org>
744 Date: Wed, 24 Feb 2010 19:10:38 +0100
745 To: help-gnu-emacs@gnu.org
746 Subject: Re: questioning let
748 >> The argument binding in arg-extern is the innermost one and consequently
749 >> the only affected one. If you make the function argument-less, it will
750 >> likely work as expected by you, affecting the binding in arg-setting.
752 > That works, thanks a lot!
753 > However, stored in some eil.el, get a compiler warning than:
756 > In arg-extern:
757 > eil.el:9:9:Warning: reference to free variable `arg'
758 > eil.el:9:17:Warning: assignment to free variable `arg'
760 > Would think a useless warning, as the compiler should know being inside a let (?)
762 The warning is completely accurate since arg-extern can be called from
763 outside arg-setting, in which case it will assign to a global variable
764 called "arg".
766 Whether or not some let-binding might be effective at the point of
767 calling arg-extern is unknown to the compiler.
769 In a Lisp variant with lexical binding (like Common Lisp or Scheme),
770 arg-extern has no way to fiddle with the let-binding of arg-setting: it
771 is completely inaccessible by name outside of arg-setting itself.
774 David Kastrup
776 From: pjb@informatimago.com (Pascal J. Bourguignon)
777 Date: Wed, 24 Feb 2010 12:59:22 +0100
778 To: help-gnu-emacs@gnu.org
779 Subject: Re: questioning let
781 let is equivalent to lambda:
783 (let ((a 1) (b 2)) (list a b)) <=> ((lambda (a b) (list a b)) 1 2)
785 defun is binding a lambda to a function cell:
787 (defun f (a b) (list a b))
788 <=> (setf (symbol-function 'f) (lambda (a b) (list a b)))
790 Therefore you can see that calling a function defined by defun is a let
791 in disguise.
793 If you transformed your code following these equivalences, you would
794 notice that you have actually TWO variables named arg, one as parameter
795 of the function arg-extern, and one as variable in the let in
796 arg-setting.
798 The setq in arg-extern will modify only the variable parameter of
799 arg-extern. Because they have the same name, this variable hides the
800 one defined in the let of arg-setting. There's no way to access it from
801 within arg-extern.
803 If they had a different name, you could modify a variable from an outer
804 dynamic scope from an inner dynamic scope, because in emacs all the
805 variables are dynamic. But it is considered very bad form to do so:
806 this is a big side effect, and what's more, one that depends on the call
807 chain. You should avoid side effects, to increase the readability and
808 debugability of your code. Therefore you should avoid setq and setf.
809 Try to write pure function, never try to modify a variable.
811 One way to write your code would be:
813 (defun do-what-you-need-to-do-with (arg)
816 (defun arg-binding ()
817 (interactive)
818 (let ((arg 1))
819 (message "before arg = %s" arg)
820 (let ((arg (arg-extern arg)))
821 (message "after arg = %s" arg)
822 (do-what-you-need-to-do-with arg))
823 (message "original arg = %s" arg)))
825 (defun arg-extern (arg)
826 (message "arg-extern before arg = %s" arg)
827 (message "arg-extern returns = %s" (1- arg))
828 (1- arg))
830 before arg = 1
831 arg-extern before arg = 1
832 arg-extern returns = 0
833 after arg = 0
834 original arg = 1
836 If you need a global variable (perhaps because you need to keep some
837 data across command invocations), the I would advise to distringuish it
838 from the other by giving it a name surrounded by stars: *var*. Then, it
839 will have a different name, and won't be shadowed (inadvertantly) by
840 inner lets, defuns or lambdas.
842 (defvar *var* 42)
844 (defun arg-extern (arg)
845 (message "arg-extern before arg = %s" arg)
846 (setf *var* (1- arg))
847 (message "arg-extern returns = %s" *var*)
848 *var*)
850 (arg-binding)
851 var* --> 0
854 __Pascal Bourguignon__
856 * real tab completion in shell-mode
858 To: help-gnu-emacs@gnu.org
859 From: Andreas Politz <politza@fh-trier.de>
860 Date: Tue, 23 Feb 2010 19:43:58 +0100
861 Subject: Re: real tab completion in shell-mode
863 Nathaniel Flath <flat0103@gmail.com> writes:
865 > Hello,
866 > Is there any way to get shell mode to use the background shell's
867 > (zsh or bash) tab completion as opposed to just tab-completing
868 > filenames?  I know about ansi-term, but I hate how it steals a lot
869 > of my keybindings and so I would prefer it if I could get this to
870 > work in shell-mode.
872 There is not really a clean way to implement this for different reasons.
875 > Thanks,
876 > Nathaniel Flath
878 A while ago, I did it anyway and wrote a special mode for bash-shells
879 which features
881 + emulation of bash completion
882 + dir-tracking (local and remote)
883 + tracking of history files
884 + displaying dir stack in header line
886 I took the opportunity to comment the code somewhat, you may give it
887 a try, if you dare:
889 http://www.fh-trier.de/~politza/emacs/bash-mode-1_0.tgz
891 Extract it somewhere in your load-path and read the commentary, or just
892 M-x bash RET
896 * reduce repeated backslashes
898 From: Teemu Likonen <tlikonen@iki.fi>
899 Date: Mon, 15 Feb 2010 10:51:28 +0200
900 To: help-gnu-emacs@gnu.org
901 Subject: Re: reduce repeated backslashes
903 2010-02-15 09:40 (+0100), Andreas Roehler wrote:
905 > don't know how to replace/reduce repeated backslashes from inside a
906 > string.
908 > Let's assume "abcdef\\\\"
910 What is the end result you want? I guess:
912 (replace-regexp-in-string "\\\\\\\\" "\\" "abcdef\\\\" nil t)
913 => "abcdef\\"
915 There are 8 backslashes in the regexp string because backslash is a meta
916 character in Lisp strings and also in regexps. 8 backslashes in a regexp
917 Lisp string means 2 literal backslashes. In the resulting string there
918 is only one backslash but it is displayed as two "\\" because it's a
919 printed representation of Lisp string.
921 * Why can't I use xargs emacs?
923 From: pjb@informatimago.com (Pascal J. Bourguignon)
924 Date: Tue, 02 Feb 2010 23:40:30 +0100
925 To: help-gnu-emacs@gnu.org
926 Subject: Re: Why can't I use xargs emacs?
928 Adam Funk <a24061@ducksburg.com> writes:
930 > The emacs command can take a list of filename arguments, so why can't
931 > I get xargs to work with it?
933 > $ find -name '*.txt' |xargs emacs -nw
934 > emacs: standard input is not a tty
936 > $ grep -rl 'foo' some/path |xargs emacs -nw
937 > emacs: standard input is not a tty
939 emacs is an interactive program. It expects its stdin and stdout to
940 be hooked to the terminal, where it can display a character matrix,
941 and from which it can read user input.
943 When you use a pipe to send paths to xargs, you disconnect the
944 terminal from the stdin, and replace it with a pipe. When xargs forks
945 and exec emacs, emacs inherit this pipe as stdin, and cannot get user
946 input, but will get instead further path from grep.
948 % echo hello > file ; ( echo -b ; echo file ) | xargs -L 1 cat
949 hello
951 To open several files in emacs, you could either use emacsclient, or
952 an emacs lisp script.
954 Launch emacs in a separate terminal: xterm -e emacs -nw &
955 In emacs, start the server: M-x server-start RET
956 In a shell, you can then type: find -name '*.txt' | xargs emacsclient -n
958 Simplier would be to just open the file in emacs:
960 Launch emacs: emacs -nw
961 Then type: C-x C-f *.txt RET
963 For the second case, you could type:
964 M-: (map nil 'find-file (split-string (shell-command-to-string "grep -rl 'foo' some/path") "\n")) RET
967 __Pascal Bourguignon__
969 From: Harald Hanche-Olsen <hanche@math.ntnu.no>
970 Date: Tue, 02 Feb 2010 18:51:39 -0500
971 To: help-gnu-emacs@gnu.org
972 Subject: Re: Why can't I use xargs emacs?
974 + Adam Funk <a24061@ducksburg.com>:
976 > The emacs command can take a list of filename arguments, so why can't
977 > I get xargs to work with it?
979 > $ find -name '*.txt' |xargs emacs -nw
980 > emacs: standard input is not a tty
982 $ find -name '*.txt' |xargs sh -c 'emacs -nw "$@" </dev/tty' -
984 (untested)
987 Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
988 - It is undesirable to believe a proposition
989 when there is no ground whatsoever for supposing it is true.
990 -- Bertrand Russell
992 To: help-gnu-emacs@gnu.org
993 From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
994 Date: Wed, 03 Feb 2010 08:23:52 +0100
995 Subject: Re: Why can't I use xargs emacs?
997 Why not a simple:
999 emacs -nw -Q $(find . -name '*.txt')
1001 Why do you want to use xargs?
1003 Bill Marcum <marcumbill@bellsouth.net> writes:
1005 > ["Followup-To:" header set to comp.unix.shell.]
1006 > On 2010-02-02, Adam Funk <a24061@ducksburg.com> wrote:
1007 >> The emacs command can take a list of filename arguments, so why can't
1008 >> I get xargs to work with it?
1010 >> $ find -name '*.txt' |xargs emacs -nw
1011 >> emacs: standard input is not a tty
1013 >> $ grep -rl 'foo' some/path |xargs emacs -nw
1014 >> emacs: standard input is not a tty
1016 > It says: standard input is not a tty. I don't normally use emacs, so there
1017 > may be a better way to do this, but you could write a function:
1018 > my_emacs () { emacs "$@" </dev/tty >&0 2>&0 ; }
1023 Thierry Volpiatto
1025 From: Adam Funk <a24061@ducksburg.com>
1026 Date: Wed, 03 Feb 2010 14:18:58 +0000
1027 To: help-gnu-emacs@gnu.org
1028 Subject: Re: Why can't I use xargs emacs?
1030 On 2010-02-02, Bit Twister wrote:
1032 > On Tue, 02 Feb 2010 20:22:17 +0000, Adam Funk wrote:
1033 >> The emacs command can take a list of filename arguments, so why can't
1034 >> I get xargs to work with it?
1036 >> $ find -name '*.txt' |xargs emacs -nw
1037 >> emacs: standard input is not a tty
1039 >> $ grep -rl 'foo' some/path |xargs emacs -nw
1040 >> emacs: standard input is not a tty
1043 > Maybe it's the -nw switch. Try
1044 > find -name '*.txt' |xargs emacs
1046 Yes, it works without -nw, but I'm often logged into an ssh server so
1047 it's faster to open emacs in the xterm.
1049 Anyway, the solution (posted by Thierry in gnu.emacs.help) turns out
1050 to be this:
1052 emacs -nw $(find . -name '*.txt')
1054 Thanks.
1057 ..the reason why so many professional artists drink a lot is not
1058 necessarily very much to do with the artistic temperament, etc. It is
1059 simply that they can afford to, because they can normally take a large
1060 part of a day off to deal with the ravages. [Amis _On Drink_]
1062 * getting emacs from launchpad
1064 From: Lennart Borgman <lennart.borgman@gmail.com>
1065 Date: Tue, 26 Jan 2010 22:46:47 +0100
1066 To: henry atting <nsmp_01@online.de>
1067 Subject: Re: bazaar question
1069 On Tue, Jan 26, 2010 at 10:31 PM, henry atting <nsmp_01@online.de> wrote:
1070 > I find it annoying that I have to grapple with bazaar if I
1071 > want to go on building emacs from source. Do I really have to pull
1072 > the whole emacs tree starting from the first published sources in the
1073 > Roman Empire?
1075 > Tried it with `bazaar branch http://bzr.savannah.gnu.org/r/emacs/trunk/'
1076 > but stopped, unpatiently, after 20 minutes.
1077 > Is this the only way to get the latest source?
1079 You can get them from Launchpad too. That is faster since they have
1080 installed the bazaar fast server (or what it is called).
1082 bzr branch lp:emacs trunk
1084 After that updates are quick (in the trunk subdir):
1086 bzr update
1088 * debug modification of a variable
1090 From: Tassilo Horn <tassilo@member.fsf.org>
1091 To: emacs-devel@gnu.org
1092 Date: Tue, 26 Jan 2010 21:26:49 +0100
1093 Subject: Re: How to debug modification to a variable value?
1095 "alin.s" <alinsoar@voila.fr> writes:
1097 > I suggest you to use the WATCH in gdb for modifications of the
1098 > variable, AWATCH for reading of the variable, etc.
1100 > To detect the location of the variable is easy: install a breakpoint
1101 > in make-variable-buffer-local that stops when exactly the variable you
1102 > are interested about is set, then see there the location of
1103 > tg-schema-alist. Afterward you can use the x* functions from .gdbinit
1104 > of emacs to debug your problem...
1106 Thanks for that explanation. I'll try that out as soon as I find some
1107 time. And also thanks for volunteering on implementing a debug facility
1108 for cases like that.
1110 Bye,
1111 Tassilo
1113 * strip mail head to fit for elbb
1115 (defun mail2elbb (&optional beg end)
1117 (interactive "*")
1118 (let ((beg (cond (beg beg)
1119 ((region-active-p)
1120 (region-beginning))
1121 (t (point-min))))
1122 (end (cond (end end)
1123 ((region-active-p)
1124 (copy-marker (region-end)))
1125 (t (point-max)))))
1126 (save-restriction
1127 (narrow-to-region beg end)
1128 (goto-char beg)
1129 (mail2elbb-intern beg end)
1130 (widen))))
1132 (defun mail2elbb-intern (beg end)
1133 (while (search-forward "=A0" nil t 1)
1134 (replace-match ""))
1135 (goto-char beg)
1136 (let ((end (progn (while
1137 (re-search-forward "^[[:alpha:]-]+To:" nil t 1) 't) (copy-marker (line-end-position)))))
1138 (goto-char beg)
1139 (beginning-of-line)
1140 (while
1141 (< (point) end)
1142 (if (looking-at "Subject:\\|From:\\|Date:\\|To:")
1143 (forward-line 1)
1144 (delete-region (line-beginning-position) (1+ (line-end-position)))))))
1146 * testing configuration
1148 From: pjb@informatimago.com (Pascal J. Bourguignon)
1149 Date: Sun, 27 Dec 2009 18:53:08 +0100
1150 To: help-gnu-emacs@gnu.org
1151 Subject: Re: testing configuration
1153 andrea <andrea.crotti.0@gmail.com> writes:
1155 > I was wondering if it would be possible to automatically check if my
1156 > emacs configuration is correct.
1157 > This can be then put in a post-commit hook to check that whenever I add
1158 > some new features or change I don't mess up somethin else
1160 > I would only need to:
1161 > - load my whole configuration
1162 > - exit and returns 0 if everything goes fine, returns another number
1163 > otherwise.
1165 > Any ideas?
1167 > I can already launch a new emacs with certain conf, but how can I get a
1168 > return value?
1170 What about:
1172 emacs -q --eval '(condition-case err (progn (load "~/.emacs") (kill-emacs 0)) (error (kill-emacs 1)))'
1177 __Pascal Bourguignon__ http://www.informatimago.com/
1179 * self-typing
1181 From: pjb@informatimago.com (Pascal J. Bourguignon)
1182 Date: Sat, 26 Dec 2009 14:32:16 +0100
1183 To: help-gnu-emacs@gnu.org
1184 Subject: Re: what is `self-typing' ?
1186 waterloo <waterloo2005@gmail.com> writes:
1188 > I can not understand a para in Elisp manual :
1190 > Lisp is unlike many other languages in that its objects are
1191 > "self-typing": the primitive type of each object is implicit in the
1192 > object itself.  For example, if an object is a vector, nothing can
1193 > treat it as a number; Lisp knows it is a vector, not a number.
1195 > What is `self-typing' ? thanks
1197 As mentionned by Eli. But this require some more explaination.
1199 Some languages are defined so that variables can hold only objects of
1200 a given type (you declare the type of the variable, or it is infered
1201 automatically at compilation time). For example, C or Haskell.
1203 Since all the types of the objects are known at compilation time from
1204 the variables they're stored in, the compiler doesn't need to generate
1205 code to store the type along with the object, or along with the
1206 variable: the type is implicity. In C, typeof(42) or int a=42; typeof(a)
1207 is computed at compilation time.
1209 Some languages are defined so that variables can hold objects of
1210 different types, at different times. In that case, the type is not
1211 attached to the variable, but must be attached to the objects
1212 themselves. For example, Lisp or Smalltalk.
1214 Since it is rarely possible to know what type of object a variable
1215 will hold (some type inference can still be applied to optimize out
1216 some function, but there remains a lot of functions where type
1217 inference doesn't restrict much the possible types, the more so when
1218 global analysis is not practical or possible), then the type of each
1219 object has to be kept with the object. In Lisp, (type-of 42) or (let
1220 ((a 42)) (type-of 42)) is computed at run-time. Notably, you can
1221 write: (type-of (read)) and depending on what you enter at run-time,
1222 will get back one type or another:
1224 M-x ielm RET
1225 *** Welcome to IELM *** Type (describe-mode) for help.
1226 ELISP> (type-of (read))
1227 Lisp expression: 42
1228 integer
1229 ELISP> (type-of (read))
1230 Lisp expression: "fourty-two"
1231 string
1232 ELISP> (type-of (read))
1233 Lisp expression: fourty-two
1234 symbol
1235 ELISP> (type-of (read))
1236 Lisp expression: (fourty two)
1237 cons
1238 ELISP>
1240 There are also languages where both things are more or less possible,
1241 you can have variables with pre-defined types holding only one type of
1242 object, and variables which can hold objects of various types, but of
1243 a same root class. For example, C++ or Java.
1245 These languages usually provide so called "Plain Old Data" types which
1246 correspond to the type of objects that can only be stored in variables
1247 with predefined types. These objects of these POD types usually
1248 don't have the type attached to them, these objects can only be stored
1249 in variables with pre-defined type. When you want to store such an
1250 object in a variable-type variable, you have to wrap it in another
1251 object, a typed object, instance of a class. In Java, you have a POD
1252 type int and an object class Integer.
1255 __Pascal Bourguignon__ http://www.informatimago.com/
1257 * Emacs uptime
1259 From: pjb@informatimago.com (Pascal J. Bourguignon)
1260 Date: Wed, 23 Dec 2009 20:16:03 +0100
1261 To: help-gnu-emacs@gnu.org
1262 Subject: Re: Some functions I hope are useful for others to
1264 [ ... ]
1266 For example, here is my emacs-uptime:
1268 (defvar com.informatimago.time/*emacs-start-time* (current-time)
1269 "For (emacs-uptime)")
1271 (defun com.informatimago.time/emacs-uptime ()
1272 "Gives Emacs' uptime, based on global var `com.informatimago.time/*emacs-start-time*'."
1273 (interactive)
1274 (let* ((st com.informatimago.time/*emacs-start-time*)
1275 (cur (current-time))
1276 (hi-diff (- (car cur) (car st)))
1277 (tot-sec (+ (ash hi-diff 16) (- (cadr cur) (cadr st))))
1278 (days (/ tot-sec (* 60 60 24)))
1279 (hrs (/ (- tot-sec (* days 60 60 24)) (* 60 60)))
1280 (mins (/ (- tot-sec (* days 60 60 24) (* hrs 60 60)) 60))
1281 (secs (/ (- tot-sec (* days 60 60 24) (* hrs 60 60) (* mins 60)) 1)))
1282 (message "Up %dd %dh %dm %ds (%s), %d buffers, %d files"
1283 days hrs mins secs
1284 (format-time-string "%a %Y-%m-%d %T" st)
1285 (length (buffer-list))
1286 (count t (buffer-list)
1287 :test-not
1288 (lambda (ignore buf)
1289 (null (cdr (assoc 'buffer-file-truename
1290 (buffer-local-variables buf)))))))))
1292 (defalias 'emacs-uptime 'com.informatimago.time/emacs-uptime)
1294 [ .... ]
1296 * Using Emacs Lisp for script writing
1298 To: help-gnu-emacs@gnu.org
1299 From: David Engster <deng@randomsample.de>
1300 Date: Sat, 19 Dec 2009 11:02:22 +0100
1301 Subject: Re: Using Emacs Lisp for script writing
1303 Andreas Politz <politza@fh-trier.de> writes:
1304 > Cecil Westerhof <Cecil@decebal.nl> writes:
1306 >> I already use 'emacs -batch' for scripting where no user input is used,
1307 >> but I would like to use it also for interactive scripting. Until now I
1308 >> did not find any usable information about this. Anybody using Emacs for
1309 >> interactive scripts?
1311 > No, but it should be noted, that this is not very difficult :
1313 > $ emacs -Q -batch -eval '(yes-or-no-p "Want some cookies ?")'
1315 You can also use the '--script' option in a shebang line:
1317 ----------------- test.sh -----------------
1318 #!/usr/bin/emacs --script
1320 (if (yes-or-no-p "Choose ")
1321 (message "You said yes")
1322 (message "You said no"))
1323 -------------------------------------------
1325 I use emacs regularly for writing scripts, since with its thousands of
1326 packages you have a huge library readily available.
1328 -David
1330 * until found
1332 From: Helmut Eller
1333 Subject: Re: until-found
1334 Date: Fri, 11 Dec 2009 17:10:38 +0100
1335 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)
1337 * Andreas Roehler [2009-12-10 13:50+0100] writes:
1339 > And here my implementation so far:
1341 > (defun until-found (search-string liste)
1342 > (let ((liste liste) element)
1343 > (while liste
1344 > (if (member search-string (car liste))
1345 > (setq element (car liste) liste nil))
1346 > (setq liste (cdr liste)))
1347 > element))
1349 This seems to be the same as:
1351 (car (member (lambda (element) (member search-string element)) liste))
1355 (find-if (lambda (element) (member search-string element)) liste)
1359 (find search-string liste :test #'member)
1363 (loop for e in liste if (member search-string e) return e)
1365 Helmut
1367 * favourite directories implementation
1369 Author: Florent Georges, source:
1370 http://fgeorges.blogspot.com/2008/01/emacs-favourite-directories.html
1372 Today, I have finally taken a look at one of the
1373 simple features I always missed in Emacs: the
1374 ability to define a set of "favourite directories."
1375 That is, a set of named directories that one can use
1376 in the minibuffer when prompted for instance to open
1377 a file. Given a set of such dirs:
1379 emacs-src -> /enter/your/path/to/emacs/sources
1380 projects -> /path/to/some/company/projects
1381 now -> @projects/the/project/I/am/working/on
1383 one can use the following path in the minibuffer to open a file,
1384 for instance using C-x C-f:
1386 @emacs-src/lisp/files.el
1387 @emacs-src/src/alloc.c
1388 @projects/great/README
1389 @now/src/some/stuff.txt
1391 Doing so, completion is available for both directory names and
1392 files under their target directories. For instance, to open the
1393 third file above, you only have to type:
1395 C-x C-f @ p <tab> g <tab> R <tab> <enter>
1397 The implementation I have just written is really simple, but
1398 useful yet. It implements all described above (including
1399 recursive defined directories, as the '@now' above.) Thanks to
1400 Emacs, I am still suprised by the facility to implement such a
1401 feature!
1403 The code was written on GNU Emacs 22.1 on Windows, but should
1404 work on any platform, and I think on Emacs 21 as well.
1406 TODO: Make a custom variable.
1407 (defvar drkm-fav:favourite-directories-alist
1408 '(("saxon-src" . "y:/Saxon/saxon-resources9-0-0-1/source/net/sf/saxon")
1409 ("kernow-src" . "~/xslt/kernow/svn-2007-09-29/kernow/trunk/src/net/sf/kernow"))
1410 "See `drkm-fav:handler'.")
1412 (defvar drkm-fav::fav-dirs-re
1413 ;; TODO: Is tehre really no other way (than mapcar) to get the list
1414 ;; of the keys of an alist?!?
1415 (concat
1416 "^@"
1417 (regexp-opt
1418 (mapcar 'car drkm-fav:favourite-directories-alist)
1420 "Internal variable that stores a regex computed from
1421 `drkm-fav:favourite-directories-alist'. WARNING: This is not
1422 updated automatically if the later variable is changed.")
1424 (defun drkm-fav:handler (primitive &rest args)
1425 "Magic handler for favourite directories.
1427 With this handler installed into `file-name-handler-alist', it is
1428 possible to use shortcuts for often used directories. It uses
1429 the mapping in the alist `drkm-fav:favourite-directories-alist'.
1431 Once installed, say you have the following alist in the mapping
1432 variable:
1434 ((\"dir-1\" . \"~/some/real/dir\")
1435 (\"dir-2\" . \"c:/other/dir/for/windows/users\"))
1437 You can now use \"@dir-1\" while opening a file with C-x C-f for
1438 instance, with completion for the abbreviation names themselves
1439 as well as for files under the target directory."
1440 (cond
1441 ;; expand-file-name
1442 ((and (eq primitive 'expand-file-name)
1443 (string-match drkm-fav::fav-dirs-re (car args)))
1444 (replace-match
1445 (cdr (assoc (match-string 1 (car args))
1446 drkm-fav:favourite-directories-alist))
1447 t t (car args)))
1448 ;; file-name-completion
1449 ((and (eq primitive 'file-name-completion)
1450 (string-match "^@\\([^/]*\\)$" (car args)))
1451 (let ((compl (try-completion
1452 (match-string 1 (car args))
1453 drkm-fav:favourite-directories-alist)))
1454 (cond ((eq t compl)
1455 (concat "@" (match-string 1 (car args)) "/"))
1456 ((not compl)
1457 nil)
1459 (concat "@" compl)))))
1460 ;; file-name-all-completions
1461 ((and (eq primitive 'file-name-all-completions)
1462 (string-match "^@\\([^/]*\\)$" (car args)))
1463 (all-completions
1464 (match-string 1 (car args))
1465 drkm-fav:favourite-directories-alist))
1466 ;; Handle any primitive we don't know about (from the info node
1467 ;; (info "(elisp)Magic File Names")).
1468 (t (let ((inhibit-file-name-handlers
1469 (cons 'drkm-fav:handler
1470 (and (eq inhibit-file-name-operation primitive)
1471 inhibit-file-name-handlers)))
1472 (inhibit-file-name-operation primitive))
1473 (apply primitive args)))))
1475 ;; Actually plug the feature into Emacs.
1476 (push '("\\`@" . drkm-fav:handler) file-name-handler-alist)
1478 * lisp interface to ispell
1480 From: Teemu Likonen <tlikonen@iki.fi>
1481 Date: Fri, 06 Nov 2009 22:05:53 +0200
1482 To: help-gnu-emacs@gnu.org
1483 Subject: Re: lisp interface to ispell ?
1485 On 2009-11-06 20:39 (+0100), Andreas Politz wrote:
1487 > Does someone have a hack, or know a different package, in order to allow
1488 > elisp access to spelling functions ? E.g. like
1490 > (spell word language)
1492 > which at least returns t or nil.
1494 Something like this?
1496 (defun my-ispell-string (word lang)
1497 (with-temp-buffer
1498 (insert word)
1499 (call-process-region (point-min) (point-max)
1500 "ispell" t t nil "-l" "-d" lang)
1501 (if (= (point-min) (point-max))
1502 t)))
1504 * Python workflow
1506 From: Simon <bbbscarter@gmail.com>
1507 Date: Fri, 6 Nov 2009 03:42:44 -0800 (PST)
1508 To: help-gnu-emacs@gnu.org
1509 Subject: Python workflow
1511 Hi, apologies in advance for a potentially numpty post.
1513 I've been using Emacs for a little while now, but I've yet to settle
1514 on a satisfactory python edit-run-debug cycle, and I was wondering
1515 what wiser minds than mine have settled upon. So far I've tried:
1517 - Edit code and run with emacs PDB. After fiddling the lisp code to
1518 automatically pick up the current buffer as the default run candidate,
1519 this is nearly okay. The main issue is that, after editing code,
1520 there's no easy way to rerun the code, so I end up killing the gud
1521 buffer every time. As such, entering and leaving the debugger is quite
1522 a few key presses and accidentally leaving it running is also easy.
1524 - Tried Pydb to similar effect.
1526 - Run everything in a seperate shell. And debug by hand. This is a
1527 little too low-fi, even for me.
1529 - Use the 'import/reload file' and 'eval def/class' functions, and run
1530 everything from the emacs python shell, using pdbtrack to help with
1531 debugging. Problems so far:
1532 - It's very easy to forget which modules you've modified and fail to
1533 reload them; because the state is carried over I continually find
1534 myself running the old versions of code I've just edited, especially
1535 if it's across several files.
1536 - More than that, sometimes the stuff I expect to reload simply
1537 doesn't, and I have no indication as to why. For example, if pdb has
1538 module open and you stick a deliberate error in the code and reload
1539 it, the minibuffer tells you the module has been loaded, even though
1540 it clearly can't have been.
1541 - I have to run pdb.pm() to debug the exception. If I run *anything*
1542 else by accident, I lose the exception context. This can be annoying
1543 if you're incompetent enough to keep making typos (I am).
1545 Does anyone have any tips on their workflow?
1547 Many thanks!
1549 Simon
1551 * strip out UTF-8 BOMs
1552 From: "Edward O'Connor" <hober0@gmail.com>
1553 Date: Thu, 5 Nov 2009 16:13:27 -0800
1554 To: emacs-devel@gnu.org
1555 Subject: find-file-literally-at-point
1559 I recently found myself in need of such a function (I was going through
1560 a bunch of files to strip out their UTF-8 BOMs, if you're curious), and
1561 it was quick enough to put together:
1563 (autoload 'ffap-guesser "ffap")
1564 (defun find-file-literally-at-point ()
1565 "Open the file at point (like `ffap') with `find-file-literally'."
1566 (interactive)
1567 (find-file-literally (ffap-guesser)))
1569 * xml and n3
1571 From: "Eric Schulte" <schulte.eric@gmail.com>
1572 Subject: Re: [Orgmode] org-babel-tangle xml text
1573 Date: Tue, 03 Nov 2009 09:18:34 -0700
1575 "Martin G. Skjæveland" <martige@ifi.uio.no> writes:
1577 > Is there a way I can add xml and n3 to the list of supported
1578 > languages? These languages does not need interpretation, so I'm
1579 > thinking it should be quite easy to add. I have fumblingly tried
1581 > (add-to-list 'org-babel-tangle-langs '("xml"))
1583 > and
1585 > (add-to-list 'org-babel-tangle-langs '("css" "xml"))
1587 > but it as no effect.
1590 Hi Martin,
1592 The attached org-mode file contains instructions for adding xml and n3
1593 to org-babel and org-babel-tangle. Note that there may be another step
1594 if the major mode for n3 is not n3-mode. Best -- Eric
1596 introduce org-babel to =xml= and =n3=
1598 #+begin_src emacs-lisp :results silent
1599 (org-babel-add-interpreter "xml")
1600 (org-babel-add-interpreter "n3")
1601 #+end_src
1603 if say =n3= should be edited using =xml-mode=, then evaluate the
1604 following adding this pair to =org-src-lang-modes=
1606 #+begin_src emacs-lisp :results silent
1607 (add-to-list 'org-src-lang-modes '("n3" . xml))
1608 #+end_src
1610 ;; inform org-babel-tangle of their existence and file extensions
1611 #+begin_src emacs-lisp :results silent
1612 (add-to-list 'org-babel-tangle-langs '("xml" "xml" nil t))
1613 (add-to-list 'org-babel-tangle-langs '("n3" "n3" nil t))
1614 #+end_src
1616 #+begin_src xml :tangle example
1617 <first>
1618 </first>
1619 #+end_src
1621 #+begin_src n3 :tangle example
1622 n3 stuff
1623 #+end_src
1625 * How to check regexp for syntax-errors?
1627 From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
1628 Date: Tue, 20 Oct 2009 01:54:56 -0600
1629 Subject: Re: How to check regexp for syntax-errors?
1630 David Combs wrote:
1631 > Isn't there some .el that that will try to parse a regexp, and tell
1632 > me where it got confused, and what to look for for errors?
1634 (defun valid-regexp-p (regexp)
1635 (interactive "sRegexp: ")
1636 (with-temp-buffer
1637 (condition-case error-data
1638 (progn
1639 (re-search-forward regexp nil t)
1641 (invalid-regexp
1642 (when (interactive-p) (message "Invalid regexp: %s" (cdr error-data)))
1643 nil))))
1646 Kevin Rodgers
1647 Denver, Colorado, USA
1649 * prefer cond over case?
1651 From: David Kastrup <dak@gnu.org>
1652 Date: Mon, 12 Oct 2009 10:03:39 +0200
1653 To: help-gnu-emacs@gnu.org
1654 Subject: Re: Perferr cond over case?
1656 pjb@informatimago.com (Pascal J. Bourguignon) writes:
1658 > Nordlöw <per.nordlow@gmail.com> writes:
1660 >> Does the use of the cl macro case() incurr some loss of performance
1661 >> compare to using cond() instead?
1663 > (macroexpand '(case (* 2 2 2 2 3)
1664 > (10 'one)
1665 > ((24 42) 'two)
1666 > ((3 33) 'three)
1667 > (otherwise 'unknown)))
1668 > -->
1669 > (let ((--cl-var-- (* 2 2 2 2 3)))
1670 > (cond ((eql --cl-var-- (quote 10)) (quote one))
1671 > ((member* --cl-var-- (quote (24 42))) (quote two))
1672 > ((member* --cl-var-- (quote (3 33))) (quote three))
1673 > (t (quote unknown))))
1675 > What do you think?
1677 Before or after byte compilation?
1680 David Kastrup
1682 * batch-mode
1684 From: Decebal <cldwesterhof@gmail.com>
1685 Newsgroups: gnu.emacs.help
1686 Date: Sat, 10 Oct 2009 11:33:17 -0700 (PDT)
1687 To: help-gnu-emacs@gnu.org
1688 Envelope-To: andreas.roehler@easy-emacs.de
1690 In a Bash script I changed:
1692 local i
1693 local length=${#1}
1695 for i in $(seq ${1}) ; do
1696 printf " Regel %${length}d voor de test\n" ${i}
1697 done >${2}
1700 emacs -batch -nw --eval='
1701 (let (
1703 (nr-of-lines '${1}')
1704 (nr-of-lines-length)
1705 (output-file "'"${2}"'"))
1706 (setq nr-of-lines-length (length (number-to-string nr-of-lines)))
1707 (dotimes (i nr-of-lines t)
1708 (insert (format (format " Regel %%%dd voor de test\n" nr-of-lines-length) (1+ i))))
1709 (write-file output-file))
1710 ' 2>/dev/null
1712 The Bash version took 293 seconds and the Emacs Lisp version 59
1713 seconds. So it is about 5 times as fast.
1714 The Emacs batch gives output like:
1715 Saving file /home/cecil/temp/inputEmacs...
1716 Wrote /home/cecil/temp/inputEmacs
1717 That is why I use the 2>/dev/null.
1718 Is there a way to circumvent the generation of the above output?
1719 Because when there is an error it is also thrown away and that is not
1720 nice.
1722 From: Vassil Nikolov <vnikolov@pobox.com>
1723 Newsgroups: gnu.emacs.help
1724 Date: Sat, 10 Oct 2009 16:55:31 -0400
1725 To: help-gnu-emacs@gnu.org
1726 Envelope-To: andreas.roehler@easy-emacs.de
1728 On Sat, 10 Oct 2009 11:33:17 -0700 (PDT), Decebal <cldwesterhof@gmail.com> said:
1729 > ...
1730 > local i
1731 > local length=${#1}
1732 > for i in $(seq ${1}) ; do
1733 > printf " Regel %${length}d voor de test\n" ${i}
1734 > done >${2}
1736 translates to
1738 emacs -Q -batch -eval '
1739 (dotimes (i '"${1}"')
1740 (princ (format " Regel %'"${#1}"'d voor de test\n" (1+ i))))
1741 ' > "${2}"
1743 ---Vassil.
1745 From: Decebal <cldwesterhof@gmail.com>
1746 Newsgroups: gnu.emacs.help
1747 Date: Sat, 10 Oct 2009 13:57:07 -0700 (PDT)
1748 To: help-gnu-emacs@gnu.org
1749 Envelope-To: andreas.roehler@easy-emacs.de
1751 On Oct 10, 10:06pm, Andreas R=F6hler <andreas.roeh...@easy-emacs.de>
1752 wrote:
1753 > > The Emacs batch gives output like:
1754 > > Saving file /home/cecil/temp/inputEmacs...
1756 > it's in files.el, save-buffer, AFAIS
1758 > (if (and modp (buffer-file-name))
1759 > (message "Saving file %s..." (buffer-file-name)))
1761 > commenting out these lines should cancel the message
1763 The problem with that is that it only works for me. But I found a way.
1764 I replaced:
1766 (write-file output-file))
1768 with:
1770 (set-visited-file-name output-file)
1771 (basic-save-buffer))
1773 But maybe there should be more consideration for the possibility that
1774 Emacs is used as a batch program.
1776 > > Wrote /home/cecil/temp/inputEmacs
1778 I still have to find something for this.
1780 That is not possible I am afraid. In the C-source there is a call to
1781 message_with_string.
1783 * vectors and lists
1785 From: pjb@informatimago.com (Pascal J. Bourguignon)
1786 Newsgroups: gnu.emacs.help
1787 Date: Fri, 09 Oct 2009 19:19:49 +0200
1788 To: help-gnu-emacs@gnu.org
1789 Envelope-To: andreas.roehler@easy-emacs.de
1791 Nordlöw <per.nordlow@gmail.com> writes:
1793 > If I have an association list say,
1795 > '(
1796 > ("key" sym1 val1 num1)
1797 > ("key2" sym2 val2 num2)
1800 > , where each entry is a fixed sequence of various objects.
1802 If this is an a-list, then you could write it as:
1804 (("key1" . (sym1 val1 num1))
1805 ("key2" . (sym2 val2 numb2)))
1807 to show that it is a list of cons cells.
1809 (a . (b c d)) <=> (a b c d), but the first notation shows that you
1810 consider it as a list of cons, and notably that you don't expect nil
1811 ie. () to be in the toplevel of the a-list.
1813 Also, if we write the a-list properly like this, we can better answer
1814 the following question:
1816 > I might
1817 > aswell use a vector to represent an entry in this alist, right?
1819 You cannot use a vector instead of the cons cells of the a-list, but
1820 you can use a vector as a value of an a-list entry. Values can be of
1821 any type. In the case of emacs lisp, you could also easily use
1822 vectors (or any other type) as keys in an a-list, since it uses equal
1823 to compare keys.
1825 (("key1" . [sym1 val1 num1])
1826 ("key2" . [sym2 val2 num2])
1827 ([?k ?e ?y ?3] . [sym3 val3 num3]))
1829 > In this case, what do I gain by using a vector instead of list?
1831 In general, vectors take half the space of lists, and access to the
1832 nth element is done in O(1) instead of O(n) with lists. However,
1833 adding or removing an element in a vector is O(n) while in the case of
1834 lists, it may be O(1) (prepending an element or removing the first
1835 element or one of the few firsts elements) or O(n) (inserting,
1836 appending an element or removing the nth element).
1838 > What about performance?: aref() faster than nth() only for large
1839 > vectors?
1841 aref has to compute a multiplication and a sum, before doing one
1842 memory load to get the element. In the case of emacs lisp, the
1843 multiplication is always by the same fixed factor AFAIK.
1845 nth has to do n memory loads to get the element.
1847 So indeed, aref will probably be faster than nth, even for indices as
1848 small as 1 or 0.
1850 > Is there vector-variant of assoc()?
1852 No. Unless you count hash-tables as a vector variant.
1854 > If not, why?
1856 Because there's no point. The advantage of using a list for a-list,
1857 apart from the historical simplicity, is that you can easily prepend
1858 the a-list with new associations, and therefore use the a-list in a
1859 purely functional way.
1861 (defun f (bindings)
1862 (let ((val (cdr (assoc 'x bindings))))
1863 (if (zerop val)
1864 (list val)
1865 (cons val (f (cons (cons 'x (1- val)) bindings))))))
1867 (let ((bindings '((y . 0) (x . 1))))
1868 (list (f (cons (cons 'x 2) bindings))
1869 (cdr (assoc 'x bindings))))
1870 ;; --> ((2 1 0) 1)
1872 Note: you could use (require 'cl) (acons key value a-list)
1873 instead of (cons (cons key value) a-list).
1875 > Has any one already written such a function?
1877 Not AFAIK, but you can write it. However, the semantics of assoc
1878 require a sequential search of the keys in the list, so there would be
1879 no gain. On the contrary, we would now have O(n) complexity to
1880 prepend a new entry to the a-vector.
1883 __Pascal Bourguignon__