highlight 16 or more occurrences
[elbb.git] / code / elbb.el
blob4e1612710395042789379c96717b83e04ff3fcea
1 * How highlight 16 or more occurrences of same character?
3 To: help-gnu-emacs@gnu.org
4 From: Oleksandr Gavenko <gavenko@bifit.com.ua>
5 Date: Mon, 13 Sep 2010 14:20:21 +0300
6 Subject: Re: How highlight 16 or more occurrences of same character?
7 Envelope-To: andreas.roehler@easy-emacs.de
9 On 13.09.2010 11:55, Deniz Dogan wrote:
10 > 2010/9/13 Oleksandr Gavenko<gavenko@bifit.com.ua>:
11 >> I use
13 >> (font-lock-add-keywords
14 >> 'c-mode
15 >> '(
16 >> ("\\(.\\)\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1\\1" 0
17 >> 'font-lock-warning-face t)
18 >> ))
20 >> but don't know how make variable back links count.
22 > Haven't tested this, but it should be similar to my reply to your
23 > other thread, with the added comma in {15,}...
25 > (font-lock-add-keywords 'c-mode '(("\\(.\\)\\1\\{15,\\}" 0
26 > 'font-lock-warning-face t)))
28 Thanks for tip. It work!
30 * define-key KEYMAP...
32 From: Miles Bader <miles@gnu.org>
33 To: Stefan Monnier <monnier@IRO.UMontreal.CA>
34 Date: Fri, 23 Jul 2010 18:32:55 +0900
35 Subject: Re: substitute-key-definition vs. define-key MAP [remap ...]
37 Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
38 > The `remap' thingy operates at the level of `key-binding'. I.e. after
39 > the command loop reads a key-sequence, it looks it up in the keymaps to
40 > turn the key-sequence into a command, and then it looks this up in the
41 > `remap' sub-keymap(s) to see if it got remapped.
43 And it's _extremely_ handy for some uses... e.g., one of my favorite
44 tricks is little minor-modes that bind [remap self-insert-command]...
46 E.g.:
48 ;;; caps-lock-mode, Miles Bader <miles@gnu.org>
50 (defvar caps-lock-mode-map
51 (let ((map (make-sparse-keymap)))
52 (define-key map [remap self-insert-command] 'self-insert-upcased)
53 map))
55 (define-minor-mode caps-lock-mode
56 "When enabled, convert all self-inserting characters to uppercase."
57 :lighter " CapsLock")
59 (defun self-insert-upcased (arg)
60 (interactive "p")
61 (setq last-command-char (upcase last-command-char))
62 (self-insert-command arg))
64 -miles
66 --
67 Politics, n. A strife of interests masquerading as a contest of
68 principles. The conduct of public affairs for private advantage.
70 * LISP-3
72 To: emacs-devel@gnu.org
73 From: David Kastrup <dak@gnu.org>
74 Date: Fri, 23 Jul 2010 12:03:55 +0200
75 Subject: Re: substitute-key-definition vs. define-key MAP [remap ...]
77 Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
79 >> If I understand you correctly, that won't get into XEmacs any time
80 >> soon. Do you really mean that `define-key' is allowed to effectively
81 >> change the command binding of a symbol globally, so that its function
82 >> definition is ignored in the context of interpreting keystrokes? Ie,
83 >> `define-key' now turns Emacs into what is effectively a LISP-3?
85 > I don't know what "ignored in the context of interpreting keystrokes"
86 > means, nor what LISP-3 means.
88 I think a LISP-2 has both function and value cells associated with a
89 symbol (never mind print name and property list in that kind of
90 accounting), making Scheme a LISP-1.
92 --
93 David Kastrup
95 * search-whitespace-regexp
97 To: help-gnu-emacs@gnu.org
98 From: Daniel Pittman <daniel@rimspace.net>
99 Date: Sat, 03 Jul 2010 23:14:59 +1000
100 Subject: Re: Why does this happen in regexp isearch?
102 Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:
104 > I open cus-edit.el.gz in Emacs and do a regexp isearch for:
106 > ^ ;;
108 > (Beginning of line, then two spaces, then two semicolons.)
110 > For some reason that I don't understand, it seems to match "beginning
111 > of line, any number of spaces OR tabs, then two semicolons". When I
112 > search for:
114 > ^ \{2\};;
116 > ...it finds what I'm looking for. Why is this?
118 (defcustom search-whitespace-regexp (purecopy "\\s-+")
119 "If non-nil, regular expression to match a sequence of whitespace chars.
120 This applies to regular expression incremental search.
121 When you put a space or spaces in the incremental regexp, it stands for
122 this, unless it is inside of a regexp construct such as [...] or *, + or ?.
123 You might want to use something like \"[ \\t\\r\\n]+\" instead.
124 In the Customization buffer, that is `[' followed by a space,
125 a tab, a carriage return (control-M), a newline, and `]+'.
127 When this is nil, each space you type matches literally, against one space."
128 :type '(choice (const :tag "Find Spaces Literally" nil)
129 regexp)
130 :group 'isearch)
132 Regards,
133 Daniel
135 ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
136 ♽ made with 100 percent post-consumer electrons
138 * tabs instead of spaces in C mode
140 Date: Sun, 2 May 2010 22:13:04 -0400
141 From: Steve Revilak <steve@srevilak.net>
142 To: help-gnu-emacs@gnu.org
143 Subject: Re: Emacs behavior
145 >From: "VICTOR TARABOLA CORTIANO"=20
147 >I would like to change the default behavior of Emacs in C mode, I
148 >use tabs instead of spaces for editing, so I changed my .emacs[1]
149 >to behave the way I want.
151 >For instance, I want:
153 >function()
155 > commands;
158 >But Emacs automatically modify the text to:
160 >function()
162 > commands;
165 >It works the way I want in text-mode, but I want syntax highligting.
167 >I would like Emacs to behave like mg or vi in C mode.
169 I've been working on a C project where most of the source code was
170 indented using tabs, and I wanted my edits to follow the same
171 formatting. A solution that worked for me was
174 * Local Variables:
175 * c-basic-offset: 8
176 * indent-tabs-mode: t
177 * End:
180 I added this Local Variables block at the bottom of each .c file I
181 needed to edit. (I didn't want to change the behavior of C mode
182 globally; instead, I merely wanted to change it in a few specific
183 files.)
185 Putting something like
187 (setq c-basic-offset 8
188 indent-tabs-mode t)
190 into ~/.emacs may give some of the behavior you're looking for.
192 You can also try
194 (setq c-indentation-style "linux")
196 For a description of cc-mode styles, these are good places to start:
198 http://www.gnu.org/software/emacs/manual/html_node/ccmode/Choosing-a-Sty=
199 le.html#Choosing-a-Style
200 http://www.gnu.org/software/emacs/manual/html_node/ccmode/Built_002din-S=
201 tyles.html#Built_002din-Styles
203 Finally, c-insert-tab-function might also be useful to you.
205 http://www.gnu.org/software/emacs/manual/html_node/ccmode/Indentation-C=
206 ommands.html#index-TAB-17
208 Steve
210 * Using Git to manage your Emacs changes
212 To: emacs-devel@gnu.org
213 From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
214 Date: Fri, 09 Apr 2010 08:04:16 +0200
215 Subject: Re: Using Git to manage your Emacs changes
217 John Wiegley <jwiegley@gmail.com> writes:
219 > On Apr 7, 2010, at 4:37 PM, Thierry Volpiatto wrote:
221 >> Why not using a stack of patchs like stgit or mercurial qpatchs.
222 >> You can then apply these patchs to bzr repo.
224 > I don't see how stgit improves anything. Also, I'm using git-bzr
225 > because I need to fetch the mirrored commits back into Git immediately
226 > after pushing, and I'm not sure how often the GitHub emacs mirror
227 > updates itself.
229 I use http://repo.or.cz/w/emacs.git
231 This repo is converted to a hg repo locally.
232 I have cloned this hg repo to another hg repo that handle qpatchs.
233 So i have three repos:
235 git, hg, hg qpatch.
237 1) on git repo: git pull
239 2) on hg repo: hg convert <last git revision>
240 (when the repo exists, hg convert is as fast as a pull)
242 3) on hg qpatch repo: hg pull
244 4) make some new patchs on hg qpatch repo (i use DVC and
245 anything-mercurial.el)
247 5) Then you can send patchs to Emacs or apply these patchs to bzr repo
248 directly.(your patchs have to be in git format)
250 The same can be done with stg.(with only 2 repo)
253 Thierry Volpiatto
254 Gpg key: http://pgp.mit.edu/
256 * Guile in Emacs (was: integer overflow)
258 From: Thomas Lord <lord@emf.net>
259 To: rms@gnu.org
260 Date: Sun, 11 Apr 2010 16:33:57 -0700
261 Subject: Re: Guile in Emacs (was: integer overflow)
263 I'd like to correct some accounts of history.
265 On Mon, 2010-03-08 at 22:19 -0500, Richard Stallman wrote:
266 > RS> If it only supports something like Emacs Lisp then it is not much of
267 > RS> an advance. Guile supports Scheme and Javascript as well as Emacs Lisp.
269 > It also supports multithreading, which IMHO is a big deal as well,
270 > perhaps more important than bignums.
272 > I think the support for multiple languages is the biggest advance.
273 > I hope support for other popular extension languages will be
274 > implemented
275 > eventually -- that was the original goal of Guile.
277 Your recollection there seems to me to be mistaken. It
278 was a long time ago but I distinctly remember things
279 differently. As I recall:
281 The original GNU Manifesto described a unix-like foundation
282 with a heavy emphasis on a Lisp-centric user-space.
284 In the early 1990s, when I worked at the FSF, several
285 of the hackers there (including me) understood the GNU
286 vision to imply that many interactive programs - not just
287 Emacs - would be extensible in a dialect of Lisp. We
288 mostly shared the opinion that Scheme was an appropriate
289 dialect.
291 Before I got to the FSF people had already started on a
292 GNU Extension Language Library - an embeddable Scheme
293 interpreter. As the (bad) "joke" goes: they code-named the
294 project "revoc" but upon reflection that's just a "cover".
295 (Get it? Spooky, ain't it?)
297 Revoc was (at least back then) going nowhere fast. Later,
298 while working on a spreadsheet program, I attempted to start
299 a new attempt at a scheme-based extension language library.
300 You were (rightly, I suppose) upset that there were higher
301 priorities. You also pointed out that I was probably wasting
302 time by starting from scratch and that I ought to have started
303 from some existing Scheme implementation. I don't recall
304 if you specifically suggested SCM but I think you might have.
305 So there were two attempts at a Scheme-based GNU extension
306 library down - and one to go.
308 A year or two later I went to work for Cygnus and we, there,
309 initially agreed to invest in making a scheme-based extension
310 language library for GNU programs. This was originally named
311 "GEL" (for GNU Extension Language) until the company lawyers
312 warned that "GEL" was a trademark for another program. It
313 was renamed Guile (a cognitive relative of "scheme" and a
314 pun for "Guy L."). You were informed of this work and were
315 encouraging. I forget at which stage of this process you
316 declared Guile to be a "GNU project" but I'm sure the extant
317 public record has it somewhere.
319 Around that time, Sun was beginning to announce and promote
320 Java. They also hired John Ousterhout and began declaring
321 "Tcl is to be the scripting language for the Internet!" Back
322 then, Sun was a particularly influential company. On a
323 technical level, Tcl was a horribly regressive language -
324 a giant step backwards in many subtle but important ways.
325 Its license was a free software license but it was uncomforable
326 at the time to have Sun pushing it so heavily because of
327 the technical problems and because of doubts about Sun's
328 motives and control over the software.
330 A faction arose within Cygnus that argued that Cygnus should
331 divest from the Guile project and adopt Tcl instead. I made
332 you aware of that and of Sun's swagger, regarding Tcl.
334 Around the same time, two of Prof. Ousterhout's graduate
335 students, John Blow and Adam Sah, were proposing that
336 the TCL language be *altered* in some small but significant
337 ways that would facilitate its translation into reasonable
338 efficient Scheme code. Their altered version of Tcl was
339 largely but not completely upward compatible with standard
340 Tcl. By applying a Scheme->C compiler to the generated
341 Scheme code, they were able to benchmark far better than
342 standard Tcl in many cases.
344 And around that same time I was independently proposing
345 similar things. Mssrs. Blow, Sah, and I compared notes
346 and so forth.
348 Around that time, also, Python was beginning to gain
349 recognition in the US (it already had a foothold in Europe).
350 Blow, Sah, and I had dinner with Von Rossum and tried to
351 persuade him to add LAMBDA and proper tail calls and perhaps
352 continuations to the language so that it could be usefully
353 translated to Scheme. He did not agree. Back at Cygnus,
354 the oppositional factions had fun lampooning lisp syntax
355 and pointing to examples like Python of what was better.
357 Some of my notes to you mysteriously transmogrified into
358 a USENET post which the archives show as having you in the
359 "From:" line and with my signature at the bottom of the
360 message. This sparked what people, to this day,
361 still call "The TCL war".
365 The "original goal" of Guile was most definitely *not*
366 to support multiple languages. Rather, that was a goal
367 that was established as a tactic in response to early
368 competition with Guile.
370 Moreover, it was *never*, in the early days, a goal
371 that Guile support other popular extension languages.
372 That was something that you added and that I (regrettably)
373 agreed to in response to the perceived threat of Tcl
374 and to a lesser extent Python.
376 And: it was *never* in those years a goal to support
377 any of those other languages exactly. It was *always*
378 a goal to have a Tcl-like syntax, a Python-like syntax,
379 and a C-like syntax for Guile Scheme. But tight
380 compatibility with those languages was *not* the goal.
381 The notion wasn't so much to "support Tcl" (or any other
382 language) as to have a hyper-flexible syntax and to
383 support, via libraries, environments with all of the
384 convenience features of a shell-like language like Tcl.
386 Early on after we adopted that tactic you and I and
387 a few others had some lengthy discussions about adding
388 Emacs Lisp to the list of languages that Guile could
389 run. We ran into some severe issues such as the
390 difference between 'NIL in Emacs lisp and '() and Scheme.
391 Perhaps not to you but to several other of us it became
392 fairly clear, back then, that a strictly compatible
393 Emacs lisp would never sit comfortably alongside a
394 proper Scheme environment. Just as we would need to make
395 a "Tcl-like" language that would break some Tcl code,
396 we would need to break some Emacs lisp code, if indeed
397 we ultimately wanted to bother trying to support any.
398 (That is part of why, at Cygnus, I built a from-scratch
399 multi-buffer, self-documenting, extensible text editor
400 in Scheme with multi-font and proportionally-spaced
401 font capabilities that, at the time, GNU Emacs wasn't
402 close to achieving. The notion was to see how far I could
403 get just leapfrogging over GNU Emacs instead of trying
404 to retrofit it.)
406 Now, years have passed. In recent years, I gather,
407 the implementation of Guile has been fairly radically
408 altered so that it is now more of a bytecode VM with
409 primitive LISP-ish types. In some sense, it has begun
410 to drift away from being primarily a Scheme to being
411 more in the category of JVM or the Mono VM. It is easier
412 to target multiple languages to such a VM but no less
413 easy to make them interoperate cleanly in a way one would
414 want to live with for the long run.
416 So Guile's goals have shifted. It was once (originally)
417 to be a tight, clean, fun Scheme environment with some
418 alternative syntaxes and specialized environments -- and
419 only later did it become the kind of heterogenous language
420 environment we see it moving towards today.
422 So, again:
424 > I hope support for other popular extension languages will be
425 > implemented eventually -- that was the original goal of Guile.
427 Nah. The heck it was. That's just not true.
429 Now, there is a separate question: is that goal to support
430 other popular extension languages a better idea or a worse
431 idea (or not importantly different) than the original goal
432 of a nice, tight, fun Scheme-based system?
434 I have my opinion ("far worse!") but it's not my intent
435 to argue for that opinion here. Just to set history straight.
437 That multi-lingual stuff was *not* the original goal of Guile.
438 On the contrary, the multi-lingual goals only came up at all
439 because of a perceived crisis sparked by Sun's announcement
440 that Tcl was to become the ubiquitous scripting language of
441 the Internet.
445 * emacs daemon.. but quietly
447 To: help-gnu-emacs@gnu.org
448 From: Richard Riley <rileyrgdev@gmail.com>
449 Date: Mon, 22 Mar 2010 20:02:22 +0100
450 Subject: Re: emacs daemon.. but quietly
452 tomas@tuxteam.de writes:
454 > On Fri, Mar 05, 2010 at 02:24:44PM +0100, Gary . wrote:
455 >> Is there any way to stop emacs, run with --daemon, printing out
456 >> details about all of the config files it is loading? At the moment I
457 >> see
459 > If I understand you correctly, you want to suppress stdout/stderr output
460 > of emacs --daemon?
462 > You might just redirect that to /dev/null like so:
464 > emacs --daemon > /dev/null 2>&1
466 > (or did I misunderstand you completely?)
468 >> ("emacs" "--quiet")
469 >> Loading charset...
470 >> Loading charset...done
471 >> (etc.) which is ugly since I want to start the server, when
472 >> appropriate, when I start my login shell by doing something like
474 >> function serverExists {
475 >> TMPDIR=${TMPDIR-/tmp};
476 >> TMPFILE="${TMPDIR}/ps-output.$$";
478 >> ps > ${TMPFILE}
479 >> grep -q 'emacs-X11' ${TMPFILE}
480 >> SERVER_STARTED=$?;
481 >> rm ${TMPFILE}
483 >> return $SERVER_STARTED;
484 >> }
486 >> if serverExists ; then
487 >> export EMACS_SERVER="emacs already started"
488 >> else
489 >> emacs --daemon --quiet
490 >> export EMACS_SERVER="emacs started here"
491 >> fi
492 >> echo $EMACS_SERVER
494 >> in my .bashrc.
496 > Hm. I don't quite understand this part. Besides, it seems a roundabout
497 > way. What are you trying to achieve?
499 > Regards
500 > -- tomás
503 As is emacs --daemon IMO.
505 In emacs 23 using the alternate editor setting. My "edit" script is:-
507 ,----
508 | #!/bin/bash
509 | # edit
510 | export GDK_NATIVE_WINDOWS=1
511 | exec emacsclient --alternate-editor="" -c "$@"
512 `----
514 Its in the man page for emacsclient and the wiki.
517 ASCII ribbon campaign ( )
518 - against HTML email X
519 & vCards / \
521 * Reading a sequence of bytes as one integer
523 Date: Sat, 13 Mar 2010 20:49:28 +0200
524 From: Eli Zaretskii <eliz@gnu.org>
525 To: help-gnu-emacs@gnu.org
526 Subject: Re: Emacs Lisp - Reading a sequence of bytes as one integer
528 > Date: Sat, 13 Mar 2010 11:56:17 -0500 (EST)
529 > From: Jeff Clough <jeff@chaosphere.com>
531 > I have a (mostly) binary file I want to inspect. There are several
532 > places in this file where I want to read a series of bytes (in this
533 > case, three consecutive bytes) and treat those bytes as a single
534 > integer. I can grab them as a buffer-substring obviously, but I'm at
535 > a loss for how to make that into the integer I need, nor can I find
536 > anything obvious that would be easier.
538 Take a look at bindat.el (it's bundled with Emacs).
540 * how to access a large datastructure efficiently?
542 To: help-gnu-emacs@gnu.org
543 From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
544 Date: Thu, 04 Mar 2010 17:09:35 +0100
545 Subject: Re: how to access a large datastructure efficiently?
547 Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
549 > Thierry Volpiatto wrote:
550 >> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
552 >>> Thierry Volpiatto wrote:
553 >>>> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
554 >>>>
555 >>>>> Hi,
556 >>>>>
557 >>>>> Christian Wittern <cwittern@gmail.com> writes:
558 >>>>>
559 >>>>>> Hi there,
560 >>>>>>
561 >>>>>> Here is the problem I am trying to solve:
562 >>>>>>
563 >>>>>> I have a large list of items which I want to access. The items are in
564 >>>>>> sequential order, but many are missing in between, like:
565 >>>>>>
566 >>>>>> (1 8 17 23 25 34 45 47 50) [in reality, there is a value associated
567 >>>>>> with this, but I took it out for simplicity]
568 >>>>>>
569 >>>>>> Now when I am trying to access with a key that is not in the list, I
570 >>>>>> want to have the one with the closest smaller key returned, so for 6
571 >>>>>> and 7 this would be 1, but for 8 and 9 this would be 8.
572 >>>>>>
573 >>>>>> Since the list will have thousands of elements, I do not want to simply
574 >>>>>> loop through it but am looking for better ways to do this in Emacs lisp.
575 >>>>>> Any ideas how to achieve this?
576 >>>>> ,----
577 >>>>> | (defun closest-elm-in-seq (n seq)
578 >>>>> | (let ((pair (loop with elm = n with last-elm
579 >>>>> | for i in seq
580 >>>>> | if (and last-elm (< last-elm elm) (> i elm)) return (list last-elm i)
581 >>>>> | do (setq last-elm i))))
582 >>>>> | (if (< (- n (car pair)) (- (cadr pair) n))
583 >>>>> | (car pair) (cadr pair))))
584 >>>>> `----
585 >>>>>
586 >>>>> That return the closest, but not the smaller closest, but it should be
587 >>>>> easy to adapt.
588 >>>> Case where your element is member of list, return it:
589 >>>>
590 >>>> ,----
591 >>>> | (defun closest-elm-in-seq (n seq)
592 >>>> | (let ((pair (loop with elm = n with last-elm
593 >>>> | for i in seq
594 >>>> | if (eq i elm) return (list i)
595 >>>> | else if (and last-elm (< last-elm elm) (> i elm)) return (list last-elm i)
596 >>>> | do (setq last-elm i))))
597 >>>> | (if (> (length pair) 1)
598 >>>> | (if (< (- n (car pair)) (- (cadr pair) n))
599 >>>> | (car pair) (cadr pair))
600 >>>> | (car pair))))
601 >>>> `----
602 >>>> For the smallest just return the car...
603 >>>>
604 >>> if n is member of the seq, maybe equal-operator too
606 >>> (<= last-elm elm)
608 >>> is correct?
610 >> No, in this case:
612 >> if (eq i elm) return (list i) ==> (i) ; which is n
614 >> and finally (car pair) ==> n
617 > Hmm, sorry being the imprecise,
618 > aimed at the first form, whose result equals the the second form once implemented this "="
620 Ok, i understand, yes, we can do what you say and it's more elegant, i
621 just notice also i forget to remove a unuseful else:
623 ,----
624 | (defun closest-elm-in-seq (n seq)
625 | (let ((pair (loop with elm = n with last-elm
626 | for i in seq
627 | if (and last-elm (<= last-elm elm) (> i elm)) return (list last-elm i)
628 | do (setq last-elm i))))
629 | (if (< (- n (car pair)) (- (cadr pair) n))
630 | (car pair) (cadr pair))))
631 `----
633 That should work the same.
634 Thanks. ;-)
637 Thierry Volpiatto
638 Gpg key: http://pgp.mit.edu/
640 To: help-gnu-emacs@gnu.org
641 From: Andreas Politz <politza@fh-trier.de>
642 Date: Thu, 04 Mar 2010 17:49:54 +0100
643 Subject: Re: how to access a large datastructure efficiently?
645 [ ... ]
647 I don't know how hash-table could help in this case, but maybe you want
648 to consider binary trees, as implemented in the avl-tree.el package.
649 Though, there is no function for finding the closest member with respect
650 to some data and a distance-function, but see below.
652 Finding a (closest) member should be constraint in logarithmic time.
654 (require 'avl-tree)
656 (setq avl (avl-tree-create '<))
658 (dotimes (i 2000)
659 (when (= 0 (% i 4))
660 (avl-tree-enter avl i)))
662 (avl-tree-member avl 80)
663 => 80
664 (avl-tree-member avl 70)
665 => nil
667 (defun avl-tree-closest-member (tree data delta-fn)
668 ;; delta-fn : data x data -> Z
669 (flet ((comp-delta (node)
670 (funcall delta-fn data
671 (avl-tree--node-data node))))
672 (let* ((node (avl-tree--root tree))
673 closest
674 (delta most-positive-fixnum)
675 (compare-function (avl-tree--cmpfun tree))
676 found)
677 (while (and node
678 (not found))
679 (when (< (comp-delta node) delta)
680 (setq delta (comp-delta node)
681 closest node))
682 (cond
683 ((funcall compare-function data (avl-tree--node-data node))
684 (setq node (avl-tree--node-left node)))
685 ((funcall compare-function (avl-tree--node-data node) data)
686 (setq node (avl-tree--node-right node)))
688 (setq found t))))
689 (if closest
690 (avl-tree--node-data closest)
691 nil))))
693 (mapcar
694 (lambda (data)
695 (avl-tree-closest-member
696 avl data (lambda (n1 n2)
697 (abs (- n1 n2)))))
698 '(1001 1002 1003 1004))
700 => (1000 1004 1004 1004)
704 * cedet and auto-complete
706 To: help-gnu-emacs@gnu.org
707 From: Richard Riley <rileyrgdev@gmail.com>
708 Date: Tue, 02 Mar 2010 08:26:20 +0100
709 Subject: Re: cedet and auto-complete
711 Richard Riley <rileyrgdev@gmail.com> writes:
713 > Just another quick poll to see if anyone has got the new cedet working
714 > with auto-complete. cedet has developed its own completion UIs but
715 > ideally I would like to use auto-complete as I do in all other
716 > modes. Has anyone a workaround or instructions for allowing this to
717 > work? Unfortunately if you only enable the minimum features which then
718 > turns off the cedet completion mechs, it also turns off the semantic
719 > navigation features which kind of detracts from its usefulness.
721 > Any help or pointer appreciated,
723 > r.
726 OK, user errror to a degree - I have now moved back to company-mode
727 (newer version is available) and made sure it was on the load path
728 before the version that came with nxhtml.
730 Works well.
732 Here is my simple setup which turns on ispell support in text-mode and
733 so works in gnus message modes.
735 (add-to-list 'load-path "~/.emacs.d/company-mode")
736 (require 'company)
737 (add-hook 'text-mode-hook (lambda()(add-to-list 'company-backends 'company-ispell)))
738 (require 'company-ispell)
739 (global-company-mode)
741 This is with cedet 1.0pre7 and company-mode 0.5
743 * hide-show squash-minor-modes
745 From: Thien-Thi Nguyen <ttn@gnuvola.org>
746 To: Andreas Roehler <andreas.roehler@online.de>
747 Subject: Re: hideshow condensed view
748 Date: Thu, 25 Feb 2010 16:21:27 +0100
750 () Andreas Roehler <andreas.roehler@online.de>
751 () Thu, 25 Feb 2010 15:24:24 +0100
753 thanks a lot maintaining hideshow.el.
755 In the last few years, i can't take any credit for its improvement.
756 See Emacs' ChangeLog for those who actually merit the appreciation...
758 Use it as default outline-mode now.
760 Cool.
762 Just one thing remains so far: hs displays an empty
763 line between headers. Would prefer a more condensed
764 view.
766 You must have good eyes (still); i use hideshow not
767 for density but for spaciousness.
769 Might it be possible to introduce a function
770 `hide-all-empty-lines', inclusive a variable which may
771 be customized?
773 Yeah, it would be possible, but i tend to think of empty lines outside
774 the (top-level) blocks as also outside the scope of hideshow. It's like
775 in the book GEB, there is the tree and there is the stuff outside the
776 tree. Get it?
778 I am already troubled by hideshow straying from its conceptual (both
779 meanings) simplicity -- a block is between matching parens, no more no
780 less -- but that's just me...
782 All this is to say, you probably should write a "squash minor mode",
783 which puts the invisible property on an overlay for text that matches
784 the empty line regexp (which of course, could be made customizable), at
785 which point my advice would be to add a hook to `hs-hide-all' to enable
786 this mode.
788 Here's a quick (but tested (lightly)) sketch:
790 (defvar empty-lines-rx "^\\s-*\\(\n\\s-*\\)+")
792 (defvar empty-lines nil
793 "List of empty lines (overlays).")
795 (defvar squash-minor-mode nil)
797 (defun squash-minor-mode ()
798 (interactive)
799 (setq squash-minor-mode (not squash-minor-mode))
800 (if squash-minor-mode
801 (save-excursion
802 (goto-char (point-min))
803 (while (re-search-forward empty-lines-rx nil t)
804 (let ((ov (make-overlay (match-beginning 0) (match-end 0))))
805 (overlay-put ov 'display "")
806 (push ov empty-lines))))
807 (mapc 'delete-overlay empty-lines)
808 (setq empty-lines nil))
809 (message "empty-lines squashing %s" (if squash-minor-mode 'on 'off)))
811 Have fun!
815 * questioning let
817 Andreas Roehler <andreas.roehler@online.de> writes:
819 > Hi,
821 > behaviour of the example code below puzzles me. Would
822 > expect setting of arg by external function, but inside
823 > `let', recognised. But remains `1'.
825 > (defun arg-setting ()
826 > (interactive)
827 > (let ((arg 1))
828 > (message "%s" arg)
829 > (arg-extern arg)
830 > (message "%s" arg)))
832 > (defun arg-extern (arg)
833 > (setq arg (1- arg)))
835 > Any help?
837 From: David Kastrup <dak@gnu.org>
838 Date: Wed, 24 Feb 2010 19:10:38 +0100
839 To: help-gnu-emacs@gnu.org
840 Subject: Re: questioning let
842 >> The argument binding in arg-extern is the innermost one and consequently
843 >> the only affected one. If you make the function argument-less, it will
844 >> likely work as expected by you, affecting the binding in arg-setting.
846 > That works, thanks a lot!
847 > However, stored in some eil.el, get a compiler warning than:
850 > In arg-extern:
851 > eil.el:9:9:Warning: reference to free variable `arg'
852 > eil.el:9:17:Warning: assignment to free variable `arg'
854 > Would think a useless warning, as the compiler should know being inside a let (?)
856 The warning is completely accurate since arg-extern can be called from
857 outside arg-setting, in which case it will assign to a global variable
858 called "arg".
860 Whether or not some let-binding might be effective at the point of
861 calling arg-extern is unknown to the compiler.
863 In a Lisp variant with lexical binding (like Common Lisp or Scheme),
864 arg-extern has no way to fiddle with the let-binding of arg-setting: it
865 is completely inaccessible by name outside of arg-setting itself.
868 David Kastrup
870 From: pjb@informatimago.com (Pascal J. Bourguignon)
871 Date: Wed, 24 Feb 2010 12:59:22 +0100
872 To: help-gnu-emacs@gnu.org
873 Subject: Re: questioning let
875 let is equivalent to lambda:
877 (let ((a 1) (b 2)) (list a b)) <=> ((lambda (a b) (list a b)) 1 2)
879 defun is binding a lambda to a function cell:
881 (defun f (a b) (list a b))
882 <=> (setf (symbol-function 'f) (lambda (a b) (list a b)))
884 Therefore you can see that calling a function defined by defun is a let
885 in disguise.
887 If you transformed your code following these equivalences, you would
888 notice that you have actually TWO variables named arg, one as parameter
889 of the function arg-extern, and one as variable in the let in
890 arg-setting.
892 The setq in arg-extern will modify only the variable parameter of
893 arg-extern. Because they have the same name, this variable hides the
894 one defined in the let of arg-setting. There's no way to access it from
895 within arg-extern.
897 If they had a different name, you could modify a variable from an outer
898 dynamic scope from an inner dynamic scope, because in emacs all the
899 variables are dynamic. But it is considered very bad form to do so:
900 this is a big side effect, and what's more, one that depends on the call
901 chain. You should avoid side effects, to increase the readability and
902 debugability of your code. Therefore you should avoid setq and setf.
903 Try to write pure function, never try to modify a variable.
905 One way to write your code would be:
907 (defun do-what-you-need-to-do-with (arg)
910 (defun arg-binding ()
911 (interactive)
912 (let ((arg 1))
913 (message "before arg = %s" arg)
914 (let ((arg (arg-extern arg)))
915 (message "after arg = %s" arg)
916 (do-what-you-need-to-do-with arg))
917 (message "original arg = %s" arg)))
919 (defun arg-extern (arg)
920 (message "arg-extern before arg = %s" arg)
921 (message "arg-extern returns = %s" (1- arg))
922 (1- arg))
924 before arg = 1
925 arg-extern before arg = 1
926 arg-extern returns = 0
927 after arg = 0
928 original arg = 1
930 If you need a global variable (perhaps because you need to keep some
931 data across command invocations), the I would advise to distringuish it
932 from the other by giving it a name surrounded by stars: *var*. Then, it
933 will have a different name, and won't be shadowed (inadvertantly) by
934 inner lets, defuns or lambdas.
936 (defvar *var* 42)
938 (defun arg-extern (arg)
939 (message "arg-extern before arg = %s" arg)
940 (setf *var* (1- arg))
941 (message "arg-extern returns = %s" *var*)
942 *var*)
944 (arg-binding)
945 var* --> 0
948 __Pascal Bourguignon__
950 * real tab completion in shell-mode
952 To: help-gnu-emacs@gnu.org
953 From: Andreas Politz <politza@fh-trier.de>
954 Date: Tue, 23 Feb 2010 19:43:58 +0100
955 Subject: Re: real tab completion in shell-mode
957 Nathaniel Flath <flat0103@gmail.com> writes:
959 > Hello,
960 > Is there any way to get shell mode to use the background shell's
961 > (zsh or bash) tab completion as opposed to just tab-completing
962 > filenames?  I know about ansi-term, but I hate how it steals a lot
963 > of my keybindings and so I would prefer it if I could get this to
964 > work in shell-mode.
966 There is not really a clean way to implement this for different reasons.
969 > Thanks,
970 > Nathaniel Flath
972 A while ago, I did it anyway and wrote a special mode for bash-shells
973 which features
975 + emulation of bash completion
976 + dir-tracking (local and remote)
977 + tracking of history files
978 + displaying dir stack in header line
980 I took the opportunity to comment the code somewhat, you may give it
981 a try, if you dare:
983 http://www.fh-trier.de/~politza/emacs/bash-mode-1_0.tgz
985 Extract it somewhere in your load-path and read the commentary, or just
986 M-x bash RET
990 * reduce repeated backslashes
992 From: Teemu Likonen <tlikonen@iki.fi>
993 Date: Mon, 15 Feb 2010 10:51:28 +0200
994 To: help-gnu-emacs@gnu.org
995 Subject: Re: reduce repeated backslashes
997 2010-02-15 09:40 (+0100), Andreas Roehler wrote:
999 > don't know how to replace/reduce repeated backslashes from inside a
1000 > string.
1002 > Let's assume "abcdef\\\\"
1004 What is the end result you want? I guess:
1006 (replace-regexp-in-string "\\\\\\\\" "\\" "abcdef\\\\" nil t)
1007 => "abcdef\\"
1009 There are 8 backslashes in the regexp string because backslash is a meta
1010 character in Lisp strings and also in regexps. 8 backslashes in a regexp
1011 Lisp string means 2 literal backslashes. In the resulting string there
1012 is only one backslash but it is displayed as two "\\" because it's a
1013 printed representation of Lisp string.
1015 * Why can't I use xargs emacs?
1017 From: pjb@informatimago.com (Pascal J. Bourguignon)
1018 Date: Tue, 02 Feb 2010 23:40:30 +0100
1019 To: help-gnu-emacs@gnu.org
1020 Subject: Re: Why can't I use xargs emacs?
1022 Adam Funk <a24061@ducksburg.com> writes:
1024 > The emacs command can take a list of filename arguments, so why can't
1025 > I get xargs to work with it?
1027 > $ find -name '*.txt' |xargs emacs -nw
1028 > emacs: standard input is not a tty
1030 > $ grep -rl 'foo' some/path |xargs emacs -nw
1031 > emacs: standard input is not a tty
1033 emacs is an interactive program. It expects its stdin and stdout to
1034 be hooked to the terminal, where it can display a character matrix,
1035 and from which it can read user input.
1037 When you use a pipe to send paths to xargs, you disconnect the
1038 terminal from the stdin, and replace it with a pipe. When xargs forks
1039 and exec emacs, emacs inherit this pipe as stdin, and cannot get user
1040 input, but will get instead further path from grep.
1042 % echo hello > file ; ( echo -b ; echo file ) | xargs -L 1 cat
1043 hello
1045 To open several files in emacs, you could either use emacsclient, or
1046 an emacs lisp script.
1048 Launch emacs in a separate terminal: xterm -e emacs -nw &
1049 In emacs, start the server: M-x server-start RET
1050 In a shell, you can then type: find -name '*.txt' | xargs emacsclient -n
1052 Simplier would be to just open the file in emacs:
1054 Launch emacs: emacs -nw
1055 Then type: C-x C-f *.txt RET
1057 For the second case, you could type:
1058 M-: (map nil 'find-file (split-string (shell-command-to-string "grep -rl 'foo' some/path") "\n")) RET
1061 __Pascal Bourguignon__
1063 From: Harald Hanche-Olsen <hanche@math.ntnu.no>
1064 Date: Tue, 02 Feb 2010 18:51:39 -0500
1065 To: help-gnu-emacs@gnu.org
1066 Subject: Re: Why can't I use xargs emacs?
1068 + Adam Funk <a24061@ducksburg.com>:
1070 > The emacs command can take a list of filename arguments, so why can't
1071 > I get xargs to work with it?
1073 > $ find -name '*.txt' |xargs emacs -nw
1074 > emacs: standard input is not a tty
1076 $ find -name '*.txt' |xargs sh -c 'emacs -nw "$@" </dev/tty' -
1078 (untested)
1081 Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
1082 - It is undesirable to believe a proposition
1083 when there is no ground whatsoever for supposing it is true.
1084 -- Bertrand Russell
1086 To: help-gnu-emacs@gnu.org
1087 From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
1088 Date: Wed, 03 Feb 2010 08:23:52 +0100
1089 Subject: Re: Why can't I use xargs emacs?
1091 Why not a simple:
1093 emacs -nw -Q $(find . -name '*.txt')
1095 Why do you want to use xargs?
1097 Bill Marcum <marcumbill@bellsouth.net> writes:
1099 > ["Followup-To:" header set to comp.unix.shell.]
1100 > On 2010-02-02, Adam Funk <a24061@ducksburg.com> wrote:
1101 >> The emacs command can take a list of filename arguments, so why can't
1102 >> I get xargs to work with it?
1104 >> $ find -name '*.txt' |xargs emacs -nw
1105 >> emacs: standard input is not a tty
1107 >> $ grep -rl 'foo' some/path |xargs emacs -nw
1108 >> emacs: standard input is not a tty
1110 > It says: standard input is not a tty. I don't normally use emacs, so there
1111 > may be a better way to do this, but you could write a function:
1112 > my_emacs () { emacs "$@" </dev/tty >&0 2>&0 ; }
1117 Thierry Volpiatto
1119 From: Adam Funk <a24061@ducksburg.com>
1120 Date: Wed, 03 Feb 2010 14:18:58 +0000
1121 To: help-gnu-emacs@gnu.org
1122 Subject: Re: Why can't I use xargs emacs?
1124 On 2010-02-02, Bit Twister wrote:
1126 > On Tue, 02 Feb 2010 20:22:17 +0000, Adam Funk wrote:
1127 >> The emacs command can take a list of filename arguments, so why can't
1128 >> I get xargs to work with it?
1130 >> $ find -name '*.txt' |xargs emacs -nw
1131 >> emacs: standard input is not a tty
1133 >> $ grep -rl 'foo' some/path |xargs emacs -nw
1134 >> emacs: standard input is not a tty
1137 > Maybe it's the -nw switch. Try
1138 > find -name '*.txt' |xargs emacs
1140 Yes, it works without -nw, but I'm often logged into an ssh server so
1141 it's faster to open emacs in the xterm.
1143 Anyway, the solution (posted by Thierry in gnu.emacs.help) turns out
1144 to be this:
1146 emacs -nw $(find . -name '*.txt')
1148 Thanks.
1151 ..the reason why so many professional artists drink a lot is not
1152 necessarily very much to do with the artistic temperament, etc. It is
1153 simply that they can afford to, because they can normally take a large
1154 part of a day off to deal with the ravages. [Amis _On Drink_]
1156 * getting emacs from launchpad
1158 From: Lennart Borgman <lennart.borgman@gmail.com>
1159 Date: Tue, 26 Jan 2010 22:46:47 +0100
1160 To: henry atting <nsmp_01@online.de>
1161 Subject: Re: bazaar question
1163 On Tue, Jan 26, 2010 at 10:31 PM, henry atting <nsmp_01@online.de> wrote:
1164 > I find it annoying that I have to grapple with bazaar if I
1165 > want to go on building emacs from source. Do I really have to pull
1166 > the whole emacs tree starting from the first published sources in the
1167 > Roman Empire?
1169 > Tried it with `bazaar branch http://bzr.savannah.gnu.org/r/emacs/trunk/'
1170 > but stopped, unpatiently, after 20 minutes.
1171 > Is this the only way to get the latest source?
1173 You can get them from Launchpad too. That is faster since they have
1174 installed the bazaar fast server (or what it is called).
1176 bzr branch lp:emacs trunk
1178 After that updates are quick (in the trunk subdir):
1180 bzr update
1182 * debug modification of a variable
1184 From: Tassilo Horn <tassilo@member.fsf.org>
1185 To: emacs-devel@gnu.org
1186 Date: Tue, 26 Jan 2010 21:26:49 +0100
1187 Subject: Re: How to debug modification to a variable value?
1189 "alin.s" <alinsoar@voila.fr> writes:
1191 > I suggest you to use the WATCH in gdb for modifications of the
1192 > variable, AWATCH for reading of the variable, etc.
1194 > To detect the location of the variable is easy: install a breakpoint
1195 > in make-variable-buffer-local that stops when exactly the variable you
1196 > are interested about is set, then see there the location of
1197 > tg-schema-alist. Afterward you can use the x* functions from .gdbinit
1198 > of emacs to debug your problem...
1200 Thanks for that explanation. I'll try that out as soon as I find some
1201 time. And also thanks for volunteering on implementing a debug facility
1202 for cases like that.
1204 Bye,
1205 Tassilo
1207 * strip mail head to fit for elbb
1209 (defun mail2elbb (&optional beg end)
1211 (interactive "*")
1212 (let ((beg (cond (beg beg)
1213 ((region-active-p)
1214 (region-beginning))
1215 (t (point-min))))
1216 (end (cond (end end)
1217 ((region-active-p)
1218 (copy-marker (region-end)))
1219 (t (point-max)))))
1220 (save-restriction
1221 (narrow-to-region beg end)
1222 (goto-char beg)
1223 (mail2elbb-intern beg end)
1224 (widen))))
1226 (defun mail2elbb-intern (beg end)
1227 (while (search-forward "=A0" nil t 1)
1228 (replace-match ""))
1229 (goto-char beg)
1230 (let ((end (progn (while
1231 (re-search-forward "^[[:alpha:]-]+To:" nil t 1) 't) (copy-marker (line-end-position)))))
1232 (goto-char beg)
1233 (beginning-of-line)
1234 (while
1235 (< (point) end)
1236 (if (looking-at "Subject:\\|From:\\|Date:\\|To:")
1237 (forward-line 1)
1238 (delete-region (line-beginning-position) (1+ (line-end-position)))))))
1240 * testing configuration
1242 From: pjb@informatimago.com (Pascal J. Bourguignon)
1243 Date: Sun, 27 Dec 2009 18:53:08 +0100
1244 To: help-gnu-emacs@gnu.org
1245 Subject: Re: testing configuration
1247 andrea <andrea.crotti.0@gmail.com> writes:
1249 > I was wondering if it would be possible to automatically check if my
1250 > emacs configuration is correct.
1251 > This can be then put in a post-commit hook to check that whenever I add
1252 > some new features or change I don't mess up somethin else
1254 > I would only need to:
1255 > - load my whole configuration
1256 > - exit and returns 0 if everything goes fine, returns another number
1257 > otherwise.
1259 > Any ideas?
1261 > I can already launch a new emacs with certain conf, but how can I get a
1262 > return value?
1264 What about:
1266 emacs -q --eval '(condition-case err (progn (load "~/.emacs") (kill-emacs 0)) (error (kill-emacs 1)))'
1271 __Pascal Bourguignon__ http://www.informatimago.com/
1273 * self-typing
1275 From: pjb@informatimago.com (Pascal J. Bourguignon)
1276 Date: Sat, 26 Dec 2009 14:32:16 +0100
1277 To: help-gnu-emacs@gnu.org
1278 Subject: Re: what is `self-typing' ?
1280 waterloo <waterloo2005@gmail.com> writes:
1282 > I can not understand a para in Elisp manual :
1284 > Lisp is unlike many other languages in that its objects are
1285 > "self-typing": the primitive type of each object is implicit in the
1286 > object itself.  For example, if an object is a vector, nothing can
1287 > treat it as a number; Lisp knows it is a vector, not a number.
1289 > What is `self-typing' ? thanks
1291 As mentionned by Eli. But this require some more explaination.
1293 Some languages are defined so that variables can hold only objects of
1294 a given type (you declare the type of the variable, or it is infered
1295 automatically at compilation time). For example, C or Haskell.
1297 Since all the types of the objects are known at compilation time from
1298 the variables they're stored in, the compiler doesn't need to generate
1299 code to store the type along with the object, or along with the
1300 variable: the type is implicity. In C, typeof(42) or int a=42; typeof(a)
1301 is computed at compilation time.
1303 Some languages are defined so that variables can hold objects of
1304 different types, at different times. In that case, the type is not
1305 attached to the variable, but must be attached to the objects
1306 themselves. For example, Lisp or Smalltalk.
1308 Since it is rarely possible to know what type of object a variable
1309 will hold (some type inference can still be applied to optimize out
1310 some function, but there remains a lot of functions where type
1311 inference doesn't restrict much the possible types, the more so when
1312 global analysis is not practical or possible), then the type of each
1313 object has to be kept with the object. In Lisp, (type-of 42) or (let
1314 ((a 42)) (type-of 42)) is computed at run-time. Notably, you can
1315 write: (type-of (read)) and depending on what you enter at run-time,
1316 will get back one type or another:
1318 M-x ielm RET
1319 *** Welcome to IELM *** Type (describe-mode) for help.
1320 ELISP> (type-of (read))
1321 Lisp expression: 42
1322 integer
1323 ELISP> (type-of (read))
1324 Lisp expression: "fourty-two"
1325 string
1326 ELISP> (type-of (read))
1327 Lisp expression: fourty-two
1328 symbol
1329 ELISP> (type-of (read))
1330 Lisp expression: (fourty two)
1331 cons
1332 ELISP>
1334 There are also languages where both things are more or less possible,
1335 you can have variables with pre-defined types holding only one type of
1336 object, and variables which can hold objects of various types, but of
1337 a same root class. For example, C++ or Java.
1339 These languages usually provide so called "Plain Old Data" types which
1340 correspond to the type of objects that can only be stored in variables
1341 with predefined types. These objects of these POD types usually
1342 don't have the type attached to them, these objects can only be stored
1343 in variables with pre-defined type. When you want to store such an
1344 object in a variable-type variable, you have to wrap it in another
1345 object, a typed object, instance of a class. In Java, you have a POD
1346 type int and an object class Integer.
1349 __Pascal Bourguignon__ http://www.informatimago.com/
1351 * Emacs uptime
1353 From: pjb@informatimago.com (Pascal J. Bourguignon)
1354 Date: Wed, 23 Dec 2009 20:16:03 +0100
1355 To: help-gnu-emacs@gnu.org
1356 Subject: Re: Some functions I hope are useful for others to
1358 [ ... ]
1360 For example, here is my emacs-uptime:
1362 (defvar com.informatimago.time/*emacs-start-time* (current-time)
1363 "For (emacs-uptime)")
1365 (defun com.informatimago.time/emacs-uptime ()
1366 "Gives Emacs' uptime, based on global var `com.informatimago.time/*emacs-start-time*'."
1367 (interactive)
1368 (let* ((st com.informatimago.time/*emacs-start-time*)
1369 (cur (current-time))
1370 (hi-diff (- (car cur) (car st)))
1371 (tot-sec (+ (ash hi-diff 16) (- (cadr cur) (cadr st))))
1372 (days (/ tot-sec (* 60 60 24)))
1373 (hrs (/ (- tot-sec (* days 60 60 24)) (* 60 60)))
1374 (mins (/ (- tot-sec (* days 60 60 24) (* hrs 60 60)) 60))
1375 (secs (/ (- tot-sec (* days 60 60 24) (* hrs 60 60) (* mins 60)) 1)))
1376 (message "Up %dd %dh %dm %ds (%s), %d buffers, %d files"
1377 days hrs mins secs
1378 (format-time-string "%a %Y-%m-%d %T" st)
1379 (length (buffer-list))
1380 (count t (buffer-list)
1381 :test-not
1382 (lambda (ignore buf)
1383 (null (cdr (assoc 'buffer-file-truename
1384 (buffer-local-variables buf)))))))))
1386 (defalias 'emacs-uptime 'com.informatimago.time/emacs-uptime)
1388 [ .... ]
1390 * Using Emacs Lisp for script writing
1392 To: help-gnu-emacs@gnu.org
1393 From: David Engster <deng@randomsample.de>
1394 Date: Sat, 19 Dec 2009 11:02:22 +0100
1395 Subject: Re: Using Emacs Lisp for script writing
1397 Andreas Politz <politza@fh-trier.de> writes:
1398 > Cecil Westerhof <Cecil@decebal.nl> writes:
1400 >> I already use 'emacs -batch' for scripting where no user input is used,
1401 >> but I would like to use it also for interactive scripting. Until now I
1402 >> did not find any usable information about this. Anybody using Emacs for
1403 >> interactive scripts?
1405 > No, but it should be noted, that this is not very difficult :
1407 > $ emacs -Q -batch -eval '(yes-or-no-p "Want some cookies ?")'
1409 You can also use the '--script' option in a shebang line:
1411 ----------------- test.sh -----------------
1412 #!/usr/bin/emacs --script
1414 (if (yes-or-no-p "Choose ")
1415 (message "You said yes")
1416 (message "You said no"))
1417 -------------------------------------------
1419 I use emacs regularly for writing scripts, since with its thousands of
1420 packages you have a huge library readily available.
1422 -David
1424 * until found
1426 From: Helmut Eller
1427 Subject: Re: until-found
1428 Date: Fri, 11 Dec 2009 17:10:38 +0100
1429 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)
1431 * Andreas Roehler [2009-12-10 13:50+0100] writes:
1433 > And here my implementation so far:
1435 > (defun until-found (search-string liste)
1436 > (let ((liste liste) element)
1437 > (while liste
1438 > (if (member search-string (car liste))
1439 > (setq element (car liste) liste nil))
1440 > (setq liste (cdr liste)))
1441 > element))
1443 This seems to be the same as:
1445 (car (member (lambda (element) (member search-string element)) liste))
1449 (find-if (lambda (element) (member search-string element)) liste)
1453 (find search-string liste :test #'member)
1457 (loop for e in liste if (member search-string e) return e)
1459 Helmut
1461 * favourite directories implementation
1463 Author: Florent Georges, source:
1464 http://fgeorges.blogspot.com/2008/01/emacs-favourite-directories.html
1466 Today, I have finally taken a look at one of the
1467 simple features I always missed in Emacs: the
1468 ability to define a set of "favourite directories."
1469 That is, a set of named directories that one can use
1470 in the minibuffer when prompted for instance to open
1471 a file. Given a set of such dirs:
1473 emacs-src -> /enter/your/path/to/emacs/sources
1474 projects -> /path/to/some/company/projects
1475 now -> @projects/the/project/I/am/working/on
1477 one can use the following path in the minibuffer to open a file,
1478 for instance using C-x C-f:
1480 @emacs-src/lisp/files.el
1481 @emacs-src/src/alloc.c
1482 @projects/great/README
1483 @now/src/some/stuff.txt
1485 Doing so, completion is available for both directory names and
1486 files under their target directories. For instance, to open the
1487 third file above, you only have to type:
1489 C-x C-f @ p <tab> g <tab> R <tab> <enter>
1491 The implementation I have just written is really simple, but
1492 useful yet. It implements all described above (including
1493 recursive defined directories, as the '@now' above.) Thanks to
1494 Emacs, I am still suprised by the facility to implement such a
1495 feature!
1497 The code was written on GNU Emacs 22.1 on Windows, but should
1498 work on any platform, and I think on Emacs 21 as well.
1500 TODO: Make a custom variable.
1501 (defvar drkm-fav:favourite-directories-alist
1502 '(("saxon-src" . "y:/Saxon/saxon-resources9-0-0-1/source/net/sf/saxon")
1503 ("kernow-src" . "~/xslt/kernow/svn-2007-09-29/kernow/trunk/src/net/sf/kernow"))
1504 "See `drkm-fav:handler'.")
1506 (defvar drkm-fav::fav-dirs-re
1507 ;; TODO: Is tehre really no other way (than mapcar) to get the list
1508 ;; of the keys of an alist?!?
1509 (concat
1510 "^@"
1511 (regexp-opt
1512 (mapcar 'car drkm-fav:favourite-directories-alist)
1514 "Internal variable that stores a regex computed from
1515 `drkm-fav:favourite-directories-alist'. WARNING: This is not
1516 updated automatically if the later variable is changed.")
1518 (defun drkm-fav:handler (primitive &rest args)
1519 "Magic handler for favourite directories.
1521 With this handler installed into `file-name-handler-alist', it is
1522 possible to use shortcuts for often used directories. It uses
1523 the mapping in the alist `drkm-fav:favourite-directories-alist'.
1525 Once installed, say you have the following alist in the mapping
1526 variable:
1528 ((\"dir-1\" . \"~/some/real/dir\")
1529 (\"dir-2\" . \"c:/other/dir/for/windows/users\"))
1531 You can now use \"@dir-1\" while opening a file with C-x C-f for
1532 instance, with completion for the abbreviation names themselves
1533 as well as for files under the target directory."
1534 (cond
1535 ;; expand-file-name
1536 ((and (eq primitive 'expand-file-name)
1537 (string-match drkm-fav::fav-dirs-re (car args)))
1538 (replace-match
1539 (cdr (assoc (match-string 1 (car args))
1540 drkm-fav:favourite-directories-alist))
1541 t t (car args)))
1542 ;; file-name-completion
1543 ((and (eq primitive 'file-name-completion)
1544 (string-match "^@\\([^/]*\\)$" (car args)))
1545 (let ((compl (try-completion
1546 (match-string 1 (car args))
1547 drkm-fav:favourite-directories-alist)))
1548 (cond ((eq t compl)
1549 (concat "@" (match-string 1 (car args)) "/"))
1550 ((not compl)
1551 nil)
1553 (concat "@" compl)))))
1554 ;; file-name-all-completions
1555 ((and (eq primitive 'file-name-all-completions)
1556 (string-match "^@\\([^/]*\\)$" (car args)))
1557 (all-completions
1558 (match-string 1 (car args))
1559 drkm-fav:favourite-directories-alist))
1560 ;; Handle any primitive we don't know about (from the info node
1561 ;; (info "(elisp)Magic File Names")).
1562 (t (let ((inhibit-file-name-handlers
1563 (cons 'drkm-fav:handler
1564 (and (eq inhibit-file-name-operation primitive)
1565 inhibit-file-name-handlers)))
1566 (inhibit-file-name-operation primitive))
1567 (apply primitive args)))))
1569 ;; Actually plug the feature into Emacs.
1570 (push '("\\`@" . drkm-fav:handler) file-name-handler-alist)
1572 * lisp interface to ispell
1574 From: Teemu Likonen <tlikonen@iki.fi>
1575 Date: Fri, 06 Nov 2009 22:05:53 +0200
1576 To: help-gnu-emacs@gnu.org
1577 Subject: Re: lisp interface to ispell ?
1579 On 2009-11-06 20:39 (+0100), Andreas Politz wrote:
1581 > Does someone have a hack, or know a different package, in order to allow
1582 > elisp access to spelling functions ? E.g. like
1584 > (spell word language)
1586 > which at least returns t or nil.
1588 Something like this?
1590 (defun my-ispell-string (word lang)
1591 (with-temp-buffer
1592 (insert word)
1593 (call-process-region (point-min) (point-max)
1594 "ispell" t t nil "-l" "-d" lang)
1595 (if (= (point-min) (point-max))
1596 t)))
1598 * Python workflow
1600 From: Simon <bbbscarter@gmail.com>
1601 Date: Fri, 6 Nov 2009 03:42:44 -0800 (PST)
1602 To: help-gnu-emacs@gnu.org
1603 Subject: Python workflow
1605 Hi, apologies in advance for a potentially numpty post.
1607 I've been using Emacs for a little while now, but I've yet to settle
1608 on a satisfactory python edit-run-debug cycle, and I was wondering
1609 what wiser minds than mine have settled upon. So far I've tried:
1611 - Edit code and run with emacs PDB. After fiddling the lisp code to
1612 automatically pick up the current buffer as the default run candidate,
1613 this is nearly okay. The main issue is that, after editing code,
1614 there's no easy way to rerun the code, so I end up killing the gud
1615 buffer every time. As such, entering and leaving the debugger is quite
1616 a few key presses and accidentally leaving it running is also easy.
1618 - Tried Pydb to similar effect.
1620 - Run everything in a seperate shell. And debug by hand. This is a
1621 little too low-fi, even for me.
1623 - Use the 'import/reload file' and 'eval def/class' functions, and run
1624 everything from the emacs python shell, using pdbtrack to help with
1625 debugging. Problems so far:
1626 - It's very easy to forget which modules you've modified and fail to
1627 reload them; because the state is carried over I continually find
1628 myself running the old versions of code I've just edited, especially
1629 if it's across several files.
1630 - More than that, sometimes the stuff I expect to reload simply
1631 doesn't, and I have no indication as to why. For example, if pdb has
1632 module open and you stick a deliberate error in the code and reload
1633 it, the minibuffer tells you the module has been loaded, even though
1634 it clearly can't have been.
1635 - I have to run pdb.pm() to debug the exception. If I run *anything*
1636 else by accident, I lose the exception context. This can be annoying
1637 if you're incompetent enough to keep making typos (I am).
1639 Does anyone have any tips on their workflow?
1641 Many thanks!
1643 Simon
1645 * strip out UTF-8 BOMs
1646 From: "Edward O'Connor" <hober0@gmail.com>
1647 Date: Thu, 5 Nov 2009 16:13:27 -0800
1648 To: emacs-devel@gnu.org
1649 Subject: find-file-literally-at-point
1653 I recently found myself in need of such a function (I was going through
1654 a bunch of files to strip out their UTF-8 BOMs, if you're curious), and
1655 it was quick enough to put together:
1657 (autoload 'ffap-guesser "ffap")
1658 (defun find-file-literally-at-point ()
1659 "Open the file at point (like `ffap') with `find-file-literally'."
1660 (interactive)
1661 (find-file-literally (ffap-guesser)))
1663 * xml and n3
1665 From: "Eric Schulte" <schulte.eric@gmail.com>
1666 Subject: Re: [Orgmode] org-babel-tangle xml text
1667 Date: Tue, 03 Nov 2009 09:18:34 -0700
1669 "Martin G. Skjæveland" <martige@ifi.uio.no> writes:
1671 > Is there a way I can add xml and n3 to the list of supported
1672 > languages? These languages does not need interpretation, so I'm
1673 > thinking it should be quite easy to add. I have fumblingly tried
1675 > (add-to-list 'org-babel-tangle-langs '("xml"))
1677 > and
1679 > (add-to-list 'org-babel-tangle-langs '("css" "xml"))
1681 > but it as no effect.
1684 Hi Martin,
1686 The attached org-mode file contains instructions for adding xml and n3
1687 to org-babel and org-babel-tangle. Note that there may be another step
1688 if the major mode for n3 is not n3-mode. Best -- Eric
1690 introduce org-babel to =xml= and =n3=
1692 #+begin_src emacs-lisp :results silent
1693 (org-babel-add-interpreter "xml")
1694 (org-babel-add-interpreter "n3")
1695 #+end_src
1697 if say =n3= should be edited using =xml-mode=, then evaluate the
1698 following adding this pair to =org-src-lang-modes=
1700 #+begin_src emacs-lisp :results silent
1701 (add-to-list 'org-src-lang-modes '("n3" . xml))
1702 #+end_src
1704 ;; inform org-babel-tangle of their existence and file extensions
1705 #+begin_src emacs-lisp :results silent
1706 (add-to-list 'org-babel-tangle-langs '("xml" "xml" nil t))
1707 (add-to-list 'org-babel-tangle-langs '("n3" "n3" nil t))
1708 #+end_src
1710 #+begin_src xml :tangle example
1711 <first>
1712 </first>
1713 #+end_src
1715 #+begin_src n3 :tangle example
1716 n3 stuff
1717 #+end_src
1719 * How to check regexp for syntax-errors?
1721 From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
1722 Date: Tue, 20 Oct 2009 01:54:56 -0600
1723 Subject: Re: How to check regexp for syntax-errors?
1724 David Combs wrote:
1725 > Isn't there some .el that that will try to parse a regexp, and tell
1726 > me where it got confused, and what to look for for errors?
1728 (defun valid-regexp-p (regexp)
1729 (interactive "sRegexp: ")
1730 (with-temp-buffer
1731 (condition-case error-data
1732 (progn
1733 (re-search-forward regexp nil t)
1735 (invalid-regexp
1736 (when (interactive-p) (message "Invalid regexp: %s" (cdr error-data)))
1737 nil))))
1740 Kevin Rodgers
1741 Denver, Colorado, USA
1743 * prefer cond over case?
1745 From: David Kastrup <dak@gnu.org>
1746 Date: Mon, 12 Oct 2009 10:03:39 +0200
1747 To: help-gnu-emacs@gnu.org
1748 Subject: Re: Perferr cond over case?
1750 pjb@informatimago.com (Pascal J. Bourguignon) writes:
1752 > Nordlöw <per.nordlow@gmail.com> writes:
1754 >> Does the use of the cl macro case() incurr some loss of performance
1755 >> compare to using cond() instead?
1757 > (macroexpand '(case (* 2 2 2 2 3)
1758 > (10 'one)
1759 > ((24 42) 'two)
1760 > ((3 33) 'three)
1761 > (otherwise 'unknown)))
1762 > -->
1763 > (let ((--cl-var-- (* 2 2 2 2 3)))
1764 > (cond ((eql --cl-var-- (quote 10)) (quote one))
1765 > ((member* --cl-var-- (quote (24 42))) (quote two))
1766 > ((member* --cl-var-- (quote (3 33))) (quote three))
1767 > (t (quote unknown))))
1769 > What do you think?
1771 Before or after byte compilation?
1774 David Kastrup
1776 * batch-mode
1778 From: Decebal <cldwesterhof@gmail.com>
1779 Newsgroups: gnu.emacs.help
1780 Date: Sat, 10 Oct 2009 11:33:17 -0700 (PDT)
1781 To: help-gnu-emacs@gnu.org
1782 Envelope-To: andreas.roehler@easy-emacs.de
1784 In a Bash script I changed:
1786 local i
1787 local length=${#1}
1789 for i in $(seq ${1}) ; do
1790 printf " Regel %${length}d voor de test\n" ${i}
1791 done >${2}
1794 emacs -batch -nw --eval='
1795 (let (
1797 (nr-of-lines '${1}')
1798 (nr-of-lines-length)
1799 (output-file "'"${2}"'"))
1800 (setq nr-of-lines-length (length (number-to-string nr-of-lines)))
1801 (dotimes (i nr-of-lines t)
1802 (insert (format (format " Regel %%%dd voor de test\n" nr-of-lines-length) (1+ i))))
1803 (write-file output-file))
1804 ' 2>/dev/null
1806 The Bash version took 293 seconds and the Emacs Lisp version 59
1807 seconds. So it is about 5 times as fast.
1808 The Emacs batch gives output like:
1809 Saving file /home/cecil/temp/inputEmacs...
1810 Wrote /home/cecil/temp/inputEmacs
1811 That is why I use the 2>/dev/null.
1812 Is there a way to circumvent the generation of the above output?
1813 Because when there is an error it is also thrown away and that is not
1814 nice.
1816 From: Vassil Nikolov <vnikolov@pobox.com>
1817 Newsgroups: gnu.emacs.help
1818 Date: Sat, 10 Oct 2009 16:55:31 -0400
1819 To: help-gnu-emacs@gnu.org
1820 Envelope-To: andreas.roehler@easy-emacs.de
1822 On Sat, 10 Oct 2009 11:33:17 -0700 (PDT), Decebal <cldwesterhof@gmail.com> said:
1823 > ...
1824 > local i
1825 > local length=${#1}
1826 > for i in $(seq ${1}) ; do
1827 > printf " Regel %${length}d voor de test\n" ${i}
1828 > done >${2}
1830 translates to
1832 emacs -Q -batch -eval '
1833 (dotimes (i '"${1}"')
1834 (princ (format " Regel %'"${#1}"'d voor de test\n" (1+ i))))
1835 ' > "${2}"
1837 ---Vassil.
1839 From: Decebal <cldwesterhof@gmail.com>
1840 Newsgroups: gnu.emacs.help
1841 Date: Sat, 10 Oct 2009 13:57:07 -0700 (PDT)
1842 To: help-gnu-emacs@gnu.org
1843 Envelope-To: andreas.roehler@easy-emacs.de
1845 On Oct 10, 10:06pm, Andreas R=F6hler <andreas.roeh...@easy-emacs.de>
1846 wrote:
1847 > > The Emacs batch gives output like:
1848 > > Saving file /home/cecil/temp/inputEmacs...
1850 > it's in files.el, save-buffer, AFAIS
1852 > (if (and modp (buffer-file-name))
1853 > (message "Saving file %s..." (buffer-file-name)))
1855 > commenting out these lines should cancel the message
1857 The problem with that is that it only works for me. But I found a way.
1858 I replaced:
1860 (write-file output-file))
1862 with:
1864 (set-visited-file-name output-file)
1865 (basic-save-buffer))
1867 But maybe there should be more consideration for the possibility that
1868 Emacs is used as a batch program.
1870 > > Wrote /home/cecil/temp/inputEmacs
1872 I still have to find something for this.
1874 That is not possible I am afraid. In the C-source there is a call to
1875 message_with_string.
1877 * vectors and lists
1879 From: pjb@informatimago.com (Pascal J. Bourguignon)
1880 Newsgroups: gnu.emacs.help
1881 Date: Fri, 09 Oct 2009 19:19:49 +0200
1882 To: help-gnu-emacs@gnu.org
1883 Envelope-To: andreas.roehler@easy-emacs.de
1885 Nordlöw <per.nordlow@gmail.com> writes:
1887 > If I have an association list say,
1889 > '(
1890 > ("key" sym1 val1 num1)
1891 > ("key2" sym2 val2 num2)
1894 > , where each entry is a fixed sequence of various objects.
1896 If this is an a-list, then you could write it as:
1898 (("key1" . (sym1 val1 num1))
1899 ("key2" . (sym2 val2 numb2)))
1901 to show that it is a list of cons cells.
1903 (a . (b c d)) <=> (a b c d), but the first notation shows that you
1904 consider it as a list of cons, and notably that you don't expect nil
1905 ie. () to be in the toplevel of the a-list.
1907 Also, if we write the a-list properly like this, we can better answer
1908 the following question:
1910 > I might
1911 > aswell use a vector to represent an entry in this alist, right?
1913 You cannot use a vector instead of the cons cells of the a-list, but
1914 you can use a vector as a value of an a-list entry. Values can be of
1915 any type. In the case of emacs lisp, you could also easily use
1916 vectors (or any other type) as keys in an a-list, since it uses equal
1917 to compare keys.
1919 (("key1" . [sym1 val1 num1])
1920 ("key2" . [sym2 val2 num2])
1921 ([?k ?e ?y ?3] . [sym3 val3 num3]))
1923 > In this case, what do I gain by using a vector instead of list?
1925 In general, vectors take half the space of lists, and access to the
1926 nth element is done in O(1) instead of O(n) with lists. However,
1927 adding or removing an element in a vector is O(n) while in the case of
1928 lists, it may be O(1) (prepending an element or removing the first
1929 element or one of the few firsts elements) or O(n) (inserting,
1930 appending an element or removing the nth element).
1932 > What about performance?: aref() faster than nth() only for large
1933 > vectors?
1935 aref has to compute a multiplication and a sum, before doing one
1936 memory load to get the element. In the case of emacs lisp, the
1937 multiplication is always by the same fixed factor AFAIK.
1939 nth has to do n memory loads to get the element.
1941 So indeed, aref will probably be faster than nth, even for indices as
1942 small as 1 or 0.
1944 > Is there vector-variant of assoc()?
1946 No. Unless you count hash-tables as a vector variant.
1948 > If not, why?
1950 Because there's no point. The advantage of using a list for a-list,
1951 apart from the historical simplicity, is that you can easily prepend
1952 the a-list with new associations, and therefore use the a-list in a
1953 purely functional way.
1955 (defun f (bindings)
1956 (let ((val (cdr (assoc 'x bindings))))
1957 (if (zerop val)
1958 (list val)
1959 (cons val (f (cons (cons 'x (1- val)) bindings))))))
1961 (let ((bindings '((y . 0) (x . 1))))
1962 (list (f (cons (cons 'x 2) bindings))
1963 (cdr (assoc 'x bindings))))
1964 ;; --> ((2 1 0) 1)
1966 Note: you could use (require 'cl) (acons key value a-list)
1967 instead of (cons (cons key value) a-list).
1969 > Has any one already written such a function?
1971 Not AFAIK, but you can write it. However, the semantics of assoc
1972 require a sequential search of the keys in the list, so there would be
1973 no gain. On the contrary, we would now have O(n) complexity to
1974 prepend a new entry to the a-vector.
1977 __Pascal Bourguignon__