skip to main | skip to sidebar
Showing posts with label emacs23. Show all posts
Showing posts with label emacs23. Show all posts

2012年10月15日

mu4e v0.9.9 is out!

I few months ago, I introduced mu4e, a modest little emacs mail client that I wrote. It seems many people picked it up, great!

what's new?

I have just released mu/mu4e version 0.9.9. There are quite a few changes, both user-visible and 'under-the-hood'. I've also spent some time on improving the manual (pdf), and I'm quite happy about it.

Some of the more visible new things in mu4e are:

  • Support for crypto (decrypting messages, signing them)
  • Support for refiling (like mutt, Wanderlust)
  • Dynamic folders (instead of hard-coding the sent/draft/trash/refile folder, they can be functions that return different folders based on the message we're dealing with, see the example below)
  • Same for the folder to save attachments
  • A lot of smaller and bigger UI improvements

Also, the core mu program has seen a lot of improvements (many of which directly improve mu4e as well)

  • Better support for non-ascii locales / character sets, such as ISO-2022-JP
  • Improved on-line help ('mu help ...')
  • Performance improvements for threaded display (~ 25% for 23K messages)

For a more complete list, see NEWS.

dynamic folders

As mentioned, mu4e now supports dynamic folders. Before, you'd set your trash folder to some static string:

(setq mu4e-trash-folder "/trash")

In some cases, you may want to have a bit more flexibility – for example, have a separate trash-folder (or sent-folder, drafts-folder, refile-folder) for private mail and work mail. You can now do something like:

(setq mu4e-trash-folder
 (lambda (msg)
 (if (and msg ;; msg may be nil
 (mu4e-message-contact-field-matches msg :to "me@work.com"))
 "/trash-work"
 "/trash")))

refiling

After I have dealt with some e-mail, I either delete it or move it to some archive folder – refiling. For this, there is now the r keybinding, and mu4e-refile-folder; and a place where dynamic folders really shine:

(setq mu4e-refile-folder
 (lambda (msg)
 (cond
 ;; messages to the mu mailing list go to the /mu folder
 ((mu4e-message-contact-field-matches msg :to
 "mu-discuss@googlegroups.com")
 "/mu")
 ;; messages sent directly to me go to /archive
 ;; also `mu4e-user-mail-address-regexp' can be used
 ((mu4e-message-contact-field-matches msg :to "me@example.com")
 "/private")
 ;; messages with football or soccer in the subject go to /football
 ((string-match "football\\|soccer" (or (mu4e-message-field msg :subject) ""))
 "/football")
 ;; everything else goes to /archive
 ;; important to have a catch-all at the end!
 (t "/archive"))))

How cool is that? After reading my inbox folder, I select all messages (C-x h), press r, and they're all moved to the right refiling folder.

crypto support

mu4e already supported signing/encrypting messages, but now it supports decryption and verifying signatures as well. This was one of the most requested new features. I think it is still a bit rough, but it has been working very well for me.

so…

I think version 0.9.9 is a great new step for mu4e. It already goes far beyond I ever planned to do. I received a lot of suggestions for new features, which is great! I'm not planning to implement all of those, but I will try to make mu4e even more programmable – it should be easy to augment mu4e with your own little elisp-snippets – the Barbapapa principle of software, already so clearly present in emacs itself.

Posted by djcb at 11:46 AM 16 comments
Labels: , , , ,

2012年08月20日

introducing mu4e, an e-mail client for emacs

background

I've haven't written too much here lately. This is because I have spent most of my emacs hacking time on mu4e, an emacs e-mail client. It's only slightly over six months old since its first release, but it has progressed rather quickly! So, I think it is time to give it an introduction to a wider audience. In future posts, I'll go into more detail.

E-mail is a very important means of communication for me; and for purposes of integration, it prefer to do my e-mail with emacs. For a long time, I used mutt with emacs as the editor; a few years back I switched to Wanderlust, and wrote a few articles about it.

There's a lot to like about Wanderlust: it's very featureful, and allows for a lot of customization. Still, there were a few things I was not fully happy with; the most important one was the speed of some operations; another annoyance was the fact that I got rather frequent cache-corruptions when using newer emacs versions.

So, what was I to do? Well, a few years back, I had written an e-mail indexer/searcher, called mu. It takes the messages in a maildir-folder, and allows you to query them. I wondered if I could use mu as the backend for an emacs-based e-mail client. So, I fired up emacs, started writing some code and some later I had a first version of… mu4e.

how does it work?

mu4e is an emacs front-end for mu; when you start it, mu4e connects to a mu server process (started on-demand). It accepts simple commands, and responds with emacs s-expressions, in asynchronous fashion. In practice, all the heavy work is done in this server process, and emacs shows the results when it is ready (usually almost instantly). Emacs does not need to wait for the backend, and things stay snappy, even with tens of thousands (or more) e-mail messages. The only operation that may still require some waiting is sending mail, since that uses the emacs built-in smtpmail, which blocks during its operation.

mu expects your e-mail messages to be stored in a maildir (a one-file-per-message system); you can get these mails there through tools like offlineimap or fetchmail. mu periodically indexes the messages, and stores the results in a Xapian database. A lot of what mu4e does is querying this database – so for example, what you see as 'my inbox folder' in the mu4e-frontend, is in fact just the result of a query of all message that happen to live in that folder. You can query for many things – message sender, subject, date, words in the body and more.

mu4e does not just query messages; it can also move messages between folders, delete them, modify their flags and so on (and afterwards update the database). All 'state' is in the file system, and the database is just a quick way to get to it; if you delete the database and then re-index, nothing is lost, and changes made with other tools (e.g. mutt) are picked up by mu as well.

trying mu4e

Some Linux distributions ship mu4e, but not necessarily a very recent version; and because mu4e is developing quickly, you may want to use the latest official release, or (if you are more adventurous) check out the git repository. You'll need GNU/Emacs 23 or 24, GLib, GMime >= 2.4 and Xapian.

After installing mu4e, you can check the mu4e manual, which should be fairly complete. In fact, one of the goals of mu4e is to make it easy to set up; for that reason, the documentation includes complete examples of how to set things up. The Getting started chapter should get you up to speed quickly.

So, give it a try if you're interested; the mu=/=mu4e project is very open to suggestions (and even bugs reports!), so feel free to put them here or subscribe to the mu mailing list.

a small tour

I'll end this with a number of screenshots, to give you a rough idea of how things look.

The main screen

When you start mu4e (M-x mu4e), you're taken to the main screen, which list the things you can do. The entries should speak for themselves. Note that you can define you're own bookmarks. In general, mu4e tries to make things as easy as possible, and provide auto-completions where possible.

The headers / view split-screen

The results of your queries are shown as a list of headers; if you click one of the headers, mu4e splits the screen horizontally (optionally, you can split the screen vertically, or only show the message view). You can customize the headers shown, re-order them and so on.

The message view supports html message, inline images, and has a mechanism to associate user-functions with messages and attachments (such as 'view in browser' or 'pipe through command'); see the manual for some examples.

The message composition view

Obviously, you can reply to messages, forward them, or compose a new message. For writing and sending messages, mu4e reuses emacs' built-in message-mode. There's support for auto-completing addresses (based on the e-mails you've sent/received before).

There's even (experimental) support for writing you're messages using org-mode, and then sending them as rich-text (html) messages.

parting thoughts

So, this was a short introduction to mu4e, barely scratching the surface, but hopefully conveying the main ideas. The manual discusses things in much more detail, and I'll write more about it in the future.

mu4e is still a young project, but, for what's it worth, I've been using it full-time for over six months, and a growing number of people are doing the same. So, if you're interested, give it try and let us know you think!

Have fun!

2011年12月22日

sauron: keeping an eye on what's going on

I'm a fairly busy person, and need to keep track of a lot of things. That includes following a bunch of internal IRC channels, attending meetings, meeting deadlines and so on. But I don't want to stare at my org-mode calendar, or flip through ERC buffers all the time.

Instead, I'd like to have one little emacs frame (window) that gathers these ('events'), and transfers me to wherever the event came from when I click it - some IRC-channel in ERC, my org-calendar etc. and other inputs. Note, using Bitlbee, you can include Facebook-contacts, GoogleTalk-buddies and Twitter-tweets, … in ERC - so, you can track just about anything.

In addition, with so many inputs, I'd also like the possibility to filter out unwanted events, and generate various light/sound effects and fireworks, proportional to the priority of the event.

For all this, I wrote a little emacs-tool called Sauron that does just that. M-x sauron-start pops up a frame that receives events, and M-x sauron-stop hides it and stops listening. It works with ERC, org, and listens for D-Bus messages; so it's pretty easy to get events from all over the place.

It's a bit of a balancing act to get all the important information while not being swamped in noise, but Sauron allows you to fine-tune it to whatever works the best for you. I've tried to have sane defaults though, so things should mostly work without too much configuration - but if you need the power, it's there. I also added some convenience functions to make it easy to get sounds and other special effects.

So - it's brand new, it is of seems-to-work-for-me-quality, and I'd like to invite others to try it out, hack it, give feedback, add new back-ends and so on – what better Christmas present to ask for!

There's documentation, examples etc. to be found in Sauron's github repository.

2011年11月21日

package management revisited

Ages ago we discussed ELPA, the emacs packaging system. It allows you to
browse through an online repository of emacs packages and install, uninstall
and upgrade them, all from within the emacs comfort zone (menu:
Options/Manage Emacs Packages).

Emacs 24.1 (a pretest is available) will include a version of ELPA --
package.el; the version included with emacs 24 supports multiple
archives. The official archive is the one provided by GNU, then there is
the current one for ELPA, but there's now a third one available: Marmalade.

Marmelade ('Spreadable Elisp') offers a very easy way for developers to
make their packages available to emacs users, and an even easier way for
users to test out interesting packages.

To use all available package repositories (GNU, ELPA and Marmalade), add
the following snippet to your .emacs:

(setq package-archives '(("ELPA" . "http://tromey.com/elpa/") 
 ("gnu" . "http://elpa.gnu.org/packages/")
 ("marmalade" . "http://marmalade-repo.org/packages/")))

This works out-of-the-box for Emacs 24; for Emacs 23, you'll need the newer
package.el, which you can get from the emacs 24 repo (if necessary, remove
the old package.el first).

Currently, there are 870 packages listed in the three repositories – a lot of
toys to play with! In fact, it is already getting quite hard to find what
you're looking for; a bit more structured way (maybe using categories) would
be useful. Also, a bit more information than the one-line description would
be very useful.

Nevertheless, it's a great addition to emacs, which will make it much easier
to play with packages – without even having to read the installation
instructions.

Posted by djcb at 10:22 PM 18 comments
Labels: ,

2010年09月27日

interview with Eric Ludlam (CEDET)

One of the notable new features of emacs 23.2 was the inclusion of CEDET. CEDET adds IDE-type functionality to emacs, and one only needs to read the responses to the 100th post to see the great interest in that.

The man behind CEDET is Eric Ludlam (EML), a long-time Emacs user and developer. He kindly answered the many questions we had for him. Thanks, Eric!

djcb: Eric, could you tell us a little bit about yourself? And about that fantastic hobby of yours, building siege engines?

EML: I manage a software engineering team at the MathWorks. The MathWorks are the creators of Matlab. In my spare time I maintain CEDET, the Matlab support for Emacs, and build replicas of ancient siege engines.

I've been building catapults of various types for use at the World Championship Punkin' Chunk since 1998. My team started with a traction trebuchet, then a HCW Trebuchet, then moved to Human Powered Centripetal, and finally to the torsion division with MistaBallista. As far as I know, Mista Ballista is the worlds largest farthest throwing currently functional ballista.

Most recently, I got to help demolish a building where I work by shooting stuff at it, which was a lot of fun.

djcb: How did you get involved with Emacs? Do you spend a lot of time with it?

EML: I've been hacking Emacs since version 18.54 on Ultrix because the alternative was vi. My first post (and thus contribution to Emacs) was to gnu.emacs.sources on June 6, 1992. I've used Emacs to work on C/C++ code for many years which inspired all the various parts of CEDET, but these days I don't get much coding time.

My work with Emacs and CEDET is seasonal currently. The summers are usually busy with family activities, and my falls are busy getting the catapult ready, so CEDET work usually happens in the winter.

djcb: Can you tell us a bit about the background of CEDET?

EML: I started with some really basic editors and eventually with LSE (Language Sensitive Editor) on VMS. LSE was pretty cool. When I switched OSes to Ultrix and was forced to use Emacs, and discovered you could script it, I was hooked. My first big Emacs hack was etalk, an implementation of Unix talk in Emacs.

In one of the Emacs related newsgroups, a spoof story floated around about how Emacs became sentient, and started writing code for Richard [Stallman] instead of the other way around. Since then I've always wanted to get Emacs to start writing my code for me. I wrote cparse.el, a regexp nightmare that could parse almost any C file into a sequence of highly detailed tags. The tags could be used to then generate code, and I had a cool comment writing utility, automatic prototype generation, and some navigation features. On the whole it failed for many reasons.

The concept, however, continued. CParse became the basic idea behind what is now the Semantic package in CEDET, though none of the old stuff remains beyond some echos in some SRecode utilities.

My end goal is to provide round-trip code management in Emacs. Emacs needs to be able to read your code, allow you to perform transformations in the code in an abstract way, and then write new code for you. Everything in CEDET is building toward that goal. It is taking a long time, and you can see it starting to take shape. Semantic can parse the code, COGRE can manipulate UML diagrams representing your code, and you can export diagrams into code through SRecode. Unfortunately this isn't a round-trip solution as the generated code currently should not replace existing hand-written code.

Can you tell us a bit about the CEDET-project?

EML: I maintain CEDET and field questions on the mailing list. There are several contributors who either own some tool in the "contrib" area, fix bugs, answer questions or apply patches for new features. There has always been someone to pick up the slack when I'm busy elsewhere, and I've greatly appreciated that.

The easiest (and most common) way to contribute code to CEDET is to provide support for some new language, or to create a language agnostic tool using the CEDET APIs. As with Emacs, you need to be able to assign copyright to the FSF to contribute to CEDET's core, but new language support or utilities can have a home in the contrib area as well.

djcb: CEDET is part of Emacs since 23.2. Can you tell us a bit about how that happened?

EML: I've been providing assignments for the parts of CEDET since 1996 or so. For Emacs 23.1, CEDET was at a stable and useful enough state that Chong Yidong was willing to do the work to integrate it into Emacs. My ability to get a legal release for CEDET in time for Emacs 23.1 failed, so it went into 23.2 instead. It is my understanding that CEDET's smart completion engine reached a performance and reliability point that made it desirable to have in Emacs.

Emacs currently includes the parts of CEDET needed to make EDE, the project management system, Semantic and it's user tools, and SRecode all work from a user perspective. Emacs lacks the Semantic development environment, needed for writing new language support, and COGRE, the UML diagram editing tool.

djcb: Are there plans to include those parts as well?

Yes. It is important for users with a stock Emacs to develop new languages using the missing Semantic development tools. I don't know if COGRE will ever go in, though I expect that this will be done via the new package management system [elpa].

djcb: Did you ever try IDEs such as Eclipse? How do you think CEDET stacks up against such programs?

EML: I have used Visual Studio more than Eclipse, and certainly watched demos on how these and other tools work.

These tools win over CEDET's features in that they usually integrate directly with the compiler, VM or whatever, and have very good completion engines and UIs that you can interact with.

CEDET wins in that you don't need a compiler, or even code that can compile for it to work and start providing useful completions. It can infer an awful lot from a project.

CEDET's language support structure is thus simple in comparison, and CEDET supports many more languages as a side effect. It also wins because it is in Emacs, and I've done my best to try and match the "Emacs Way". For an Emacs user, this is intuitive, but can appear quirky to outsiders.

djcb: What about other development tools for in emacs?

EML: There are a lot of language specific solutions like GCCSense, slime, JDEE, and others out there. These projects are great in that they take a language, and push it to the edge of what you can do, and the users generally love that stuff. When someone wants to do the same thing, like when CSDE started for C#, and it tried to copy JDEE, it was just that, a copy that didn't quite make it.

It is my hope that CEDET will become the target of choice for users who want to make their language support in Emacs the best. They will save a lot of time doing so as well. The same infrastructure for integrating in external tools can be used to get improved results out of CEDET, but CEDET will handle converting that into a representation that would then allow any tool built on CEDET to work. This is the same model that worked well for comint.el, and gud.el.

Yasnippet is a bit different in the way it "competes" with SRecode. My first implementation of SRecode tried recycling tempo templates, but I couldn't get it to work. In fact all the template systems I investigated fell short of what I was trying to do, so I had to roll my own, and ended up using a variant of the Google template format.

The key difference is that the goal was for SRecode to provide a series of base templates for code generation. A tool writer would then write some tool to generate code. A user would then use the tool, and say "This is great, how do I change where the { goes?"

The answer is to override the template with that detail in it without interfering with the system templates. That only works if the templates are sufficiently granular that the changed template can be simple. Template reuse needs to be high so that if your company formats your methods as:

int mymethod() { implementme() };

instead of

int mymethod() {
}

that one template change will allow this to happen for all code generated from every tool.

Thus, the audience for yasnippet and SRecode is quite different. Of course you could do yasnippet like things with SRecode if someone took the time to improve the field-editing feature in SRecode, but that has not been my focus.

djcb: Do you follow the overall Emacs development process? Are there things you would like to see changed/improved?

EML: I watch the emacs-devel mailing list, mainly to see if anything related to CEDET goes by that I can help with, or what the latest cool feature might be. My first contribution of Speedbar to Emacs in Emacs 20 helped drive some features related to overlines, boxes, and other face attributes that appeared in Emacs 21.

In the future, once CEDET and Emacs cross merge techniques are hashed out, I would expect some key parts that need performance improvements might move into C. Another part of CEDET that I'd love to see become bound closer to Emacs is mode-local.el. It tries to simulate mode-local variables and mode-local functions. This is critical in a complex system like CEDET that needs to provide a language support author with fine grained control. There are good reasons not to make what is currently implemented "the Emacs way", but it would be nice to resolve those and enable mode authors a with a more powerful way to customize the user experience.

djcb: Do you have specific plans for CEDET in the future?

EML: Here is the short list:

  • Improve Emacs/CEDET cross merging
  • Offload tag storage to an external process - needed for scalability
  • Design/define a "CEDET mode" as a way of simplifying the confusing array of distinct tools and modes that make up CEDET now.
  • Finish the smart-context menu project
  • Resolve the "code replacement" problem of parsing a block of code, transforming it, and re-creating that code in place reliably.
djcb: In addition to all these 'generic' improvements, are there specific areas where new contributors could make a difference?

EML: Supporting new "stuff" in CEDET is one big win. Stuff can be:

  • New project types under EDE to ease transition from something like Visual Studio to Emacs.
  • Language support, such as parsers, or mode overrides. Finding ways to take existing cool tools, like JDE's beanshell, or slime's inferior lisp process and allowing it to do work for CEDET is another big win.
  • Templates for code generation in new languages.

Tool writing would also be good. JDEE's author Paul Kinnucan converted many bits of JDEE to CEDET and co-designed many of CEDET's parts along the way, such as semanticdb, and that was a huge help. ECB's current maintainer Klaus has also had a big impact on the way concepts are abstracted to a tool that depends on CEDET.

Naturally, joining the mailing list and fixing reported bugs and improving the doc is also a huge help, but not as exciting as writing new code. :)

djcb: Finally, many people want to start using CEDET, but it seems they have a bit of trouble to get started. Do you have any recommendations for them?

EML: Start with the cedet.info file which has many of the common setup configurations in it. If you run into something not explained well or at all, be sure to join the mailing list and be specific about how that doc failed. Very few questions on the mailing list refer to the doc, so the doc is rarely improved in a way that can help others.

Another good starting point is Alex Ott's article A Gentle Introduction to CEDET, which is very helpful.

Thanks a lot for your time, Eric! Wishing you a lot of success with CEDET and all your other projects!
Posted by djcb at 7:42 AM 3 comments

2009年07月28日

emacs 23 has been released!

Emacs 23(.1) has been released! After only just over two years since the previous version, emacs 23 has been released on July 29 2009. Time to celebrate! And a big thanks all the talented hackers that made it possible!

Emacs 23 brings many new features. Some of those have been discussed before in emacs-fu, and of course you can get the full list from the NEWS-file (C-h n). This is just a list of some of the highlights, in particular the end-user-visible ones. Let's go through them - of course I cannot mention all of them, so feel free to add your favorite one in the comments.

fonts & anti-aliasing

Finally, emacs 23 brings support for anti-aliased fonts to X (Mac/Windows users have had this for a while). If you're running emacs on X, this one change is enough to never want to go back to an older version of Emacs again.

The new font system mentioned in some posts before: setting fonts and emacs 23.

support for D-Bus and Zeroconf

You can now call other services on the desktop using the DBUS IPC system (popular on X); using d-bus: an example shows how to communicate with the Tomboy note taker program from emacs. As more and more desktop services are accessible using D-BUS, this offers great opportunities for better integrating emacs with the rest of the desktop. For example, one could imagine that emacs could communicate with a network manager when it needs a connection. Or it could show a desktop notification when an appointment is near. And all without adding hard dependencies or calling external binaries.

Using Zeroconf is also quite easy; for example, to get a list of all zeroconf-support printers, you could do something silly like:

(require 'zeroconf)
(zeroconf-init)
(dolist (srv (zeroconf-list-services "_printer._tcp"))
 (insert (format "\nprinter: %s" (nth 2 srv))))

to insert a list of the available printers in your current buffer. As with D-Bus, it's really an enabler for a lot of cool things.

support for 'headless' emacs-daemon

If you have a lot of support packages, emacs startup can be a bit slow. However, emacs 23 brings emacs --daemon, which enables you to start emacs in the background (for example when you log in). You can instantly pop up new emacs windows (frames) with emacsclient. Of course, you could already have an emacs 'server' in older versions, but being able to start it in the background makes this a much nicer solution.

The Emacs-daemon was discussed in emacs-fu in emacs –daemon and windows and daemons (for MS-Windows). Popping up new emacs windows is so fast that you can use emacs for any editing job, for example as an editor for an email program, or for quick rememember notes.

You can even combine X and console clients in one session now.

Emacs now support Xembed

This enables you to embed emacs in other programs (on X) using XEmbed. Haven't played with that yet. There is some more information in EmacsWiki/Xembed.

Support for frame opacity

You can now make you emacs frames transparent. Discussed before in transparent emacs. Not sure how useful this is, but it surely looks nice :)

Internationalization

Emacs's character set is a superset of Unicode, with about four times the space available. That should be enough for the foreseeable future… There are also many new character sets available, as well as new language environments, such as Chinese-GB18030, Khmer, Bengali, Punjabi, Gujarati, Oriya, Telugu, Sinhala, and TaiViet.

Note that, internally, emacs uses UTF-8 now.

New defaults

  • Screen motion now goes by screen lines by default, that is when you move the cursor up or down, it follows the line as you see them. Nice.
  • Transient mark mode (visible selection) is now on by default, so no need for (transient-mark-mode t) in your .emacs anymore. However, you still need to put (delete-selection-mode t) if you like replace the current selection with your typing.
  • Also shift-select mode is enabled by default, so you can select with shift + the arrow keys.

New modes and packages, and updated ones

Posted by djcb at 11:01 PM 13 comments
Labels:

2009年05月15日

using the systems 'trash' when deleting files

A short tip today.

When you delete files and directories in Emacs 23 (say, with dired), instead of losing the files until the end of times (or at least until the singularity), you can move them to the 'trashcan', by whatever name that rose comes in your system, 'Trash' or 'Recycle Bin'…

To enable this, put the following in your .emacs:

(setq delete-by-moving-to-trash t)
There is one problem - a bug? I am using Ubuntu 9.04, which follows the Freedesktop Trash Spec; it moves delete file in ~/.local/share/Trash, together with some metadata, so it can restore the file to their original location. However, emacs follows some older convention, ie. to move the file to ~/.Trash, and without any metadata.

You can partially fix this by making ~/.Trash a symlink to ~/.local/share/Trash/files/, but of course that does not get you the metadata.

Posted by djcb at 9:03 PM 8 comments
Labels:

2009年02月18日

transparent emacs

It may not be so useful, but emacs23 allows you to manipulate the transparency of your emacs frames (windows). If you use Windows or X with a compositing window manager on X, you can make your windows transparent. Examples of compositing window managers are Compiz/Beryl and even the good-old Metacity (gconftool-2 -s '/apps/metacity/general/compositing_manager' --type bool true).

The following code for your .emacs makes it easy to set transparency from within emacs:

(defun djcb-opacity-modify (&optional dec)
 "modify the transparency of the emacs frame; if DEC is t,
 decrease the transparency, otherwise increase it in 10%-steps"
 (let* ((alpha-or-nil (frame-parameter nil 'alpha)) ; nil before setting
 (oldalpha (if alpha-or-nil alpha-or-nil 100))
 (newalpha (if dec (- oldalpha 10) (+ oldalpha 10))))
 (when (and (>= newalpha frame-alpha-lower-limit) (<= newalpha 100))
 (modify-frame-parameters nil (list (cons 'alpha newalpha))))))
 ;; C-8 will increase opacity (== decrease transparency)
 ;; C-9 will decrease opacity (== increase transparency
 ;; C-0 will returns the state to normal
(global-set-key (kbd "C-8") '(lambda()(interactive)(djcb-opacity-modify)))
(global-set-key (kbd "C-9") '(lambda()(interactive)(djcb-opacity-modify t)))
(global-set-key (kbd "C-0") '(lambda()(interactive)
 (modify-frame-parameters nil `((alpha . 100)))))
Now, you can make make emacs more transparent (less opaque) by pressing C-9, while C-8 has the opposite effect. C-0 brings us back to normality.

Admittedly, window transparency is a classical solution-looking-for-a-problem. But let that not stop us from using it -- now we can watch full-screen movies while still using emacs. That, my friends, is progress.

Posted by djcb at 10:49 PM 20 comments
Labels:

2009年02月11日

emacs --daemon

Emacs23 has gone in pre-test. As I mentioned before, there are a lot of improvements, and there's little reason not to migrate to this new version. YMMV, of course. As always, you can see all the news with C-h n (Ctrl-H and then n) -- but obviously you need emacs 23 to see the news for emacs 23.

There's even an easter egg, as Giorgos Keramidas notes: M-x butterfly, inspired by xkcd...

A more useful new feature that I'll discuss here, is emacs --daemon. Since many versions, you can set up emacs as an emacs-server. The idea is that you start one emacs instance (the 'server'), and you can then use emacsclient to quickly pop up a new emacs-frame (window). This new frame is not a new emacs instance, it's just a new frame (window) for the already-running emacs. The nice thing is that emacsclient is very quick - it doesn't need to parse all the startup packages or your 5000-line .emacs. You could activate it by putting (server-start) in your .emacs, or calling M-x server-start. I've been happily using that for years with mutt.

Those were happy years. Still, things could be better. Emacs-client/server had its limitations: first, an emacs could have graphical or console (tty) clients, but not both at the same time. Second, you always needed to start emacs in the foreground before you could use emacslient.

Both of these limitations have gone now -- hurray! You simply start emacs as:

 $ emacs --daemon
and it starts running in the background. After that, you can start emacs client frames (windows) using:
 $ emacsclient -c
. This will give you a graphical version when running X, or a terminal (console) version otherwise. If you want a terminal version even in windows-mode, use:
 $ emacsclient -t
. If you don't want the controlling terminal to wait for the emacsclient to finish, you can add the -n argument, so:
 $ emacsclient -c -n
and you can even specify an alternate editor if emacs is not yet running, so:
 $ emacsclient -c -a nano # if all else fails...
Of course, you can also start emacs itself as the 'alternate'.

Now, my new way to run emacs is a follows:

  1. I start emacs in the background (as daemon) when logging into X; this can be done automatically by adding to make emacs --daemon to your list of startup-programs. In GNOME, this can be set through the Preferences/Sessions/Startup Programs-menu. I am sure other environments have something similar. Alternatively, you could put emacs --daemon & in ~/.xinitrc.
  2. I fire up emacs frames (windows) with emacsclient -c (or emacsclient -t to run it in a console);
  3. That's it!
If you want to terminate emacs outside emacs, you'll have to kill it by hand (AFAIK) -- something like
 $ pkill -TERM -u $USER emacs
Make sure you have no unsaved data, and no other emacsen running...

You also might want to set some influential environment variables in your .~/.bashrc, ~/.zshenv, ..., so other programs will automatically use an emacsclient when available; e.g.,

 EDITOR="emacsclient -c"
 VISUAL="emacsclient -c"
 
With emacs --daemon there's no longer any need to use vi for quick-editing some file. In other words: alias vi="emacsclient -c"...
Posted by djcb at 9:06 PM 28 comments
Labels:

2009年01月24日

using d-bus: an example

In the previous entry, I mentioned Emacs version 23. This time, let's see what we can do with one of its new features: D-Bus-support. As you might know, D-Bus is an IPC system used on Linux/Unix to communicate between applications; it's a kind-of successor to systems like Bonobo (Gnome) and KParts (KDE). With support for D-Bus in Emacs, it's easy to control other applications. More and more programs are providing D-Bus interfaces.

As a semi-useful example of that, let's look at using D-Bus to control the Tomboy Note Taker application. Tomboy takes a novel approach (at least for me) at note taking -- your notes are connected like a wiki. Tomboy was originally designed and written by Alex Graveley, who has a talent for coming up with interesting ideas, and then turning them into software. Anyhow, I only use Tomboy as example of the use of D-Bus from emacs; there are many other interesting programs controllable through D-Bus.

Note, I won't discuss the details of D-Bus itself here; there's a lot of good material available already. Specifically, for some more background on using D-Bus with emacs, I can recommend the documentation (info-page) that comes with Emacs-23.

Back to Tomboy. First, let's make it easy to call Tomboy. It obviously assumes you have Tomboy installed, but it does not have to be running. First, a helper function that uses the new dbus-call-method-function, sets the service, path and interface names for Tomboy; this way, we don't have to specify them for each call:

(require 'dbus)
(defun djcb-call-tomboy (method &rest args)
 "call the tomboy method METHOD with ARGS over dbus"
 (apply 'dbus-call-method 
 :session ; use the session (not system) bus
 "org.gnome.Tomboy" ; service name
 "/org/gnome/Tomboy/RemoteControl" ; path name
 "org.gnome.Tomboy.RemoteControl" ; interface name
 method args))

Then, djcb-tomboy-create-note-region creates a new note from the region (selection) use CreateNamedNote and SetNoteContents; it even does some rudimentary error checking:

(defun djcb-tomboy-create-note-region (b e name)
 "Create a new note with in the Tomboy notetaker from region"
 (interactive "r\nsName for new Tomboy note:")
 (let ((note-uri (djcb-call-tomboy "CreateNamedNote" name)))
 (if (and note-uri (> (length note-uri) 0))
 (djcb-call-tomboy "SetNoteContents" note-uri 
 (concat name "\n" (buffer-substring b e)))
 (message "hmmm... it did not work. maybe try a different name"))))
With djcb-tomboy-insert-note-contents we can insert the contents of some tomboy note into the current buffer, using FindNote/GetNoteContents There's auto-completion available for the name of the note, using ListAllNotes:
(defun djcb-tomboy-insert-note-contents (name)
 "Insert Tomboy note with NAME"
 (interactive 
 (list (let ((lst))
 (dolist (uri (djcb-call-tomboy "ListAllNotes"))
 (add-to-list 'lst (djcb-call-tomboy "GetNoteTitle" uri)))
 (completing-read "Name of Tomboy Note:" lst))))
 (let ((note-uri (djcb-call-tomboy "FindNote" name)))
 (when note-uri
 (insert (djcb-call-tomboy "GetNoteContents" note-uri)))))

So, easy enough to do, even for an Elisp novice like myself. Again, this is more to show the use of dbus from emacs than about Tomboy itself -- but it is somewhat useful. I'm actually not using Tomboy so much anymore - org-mode better fits my emacs-centric workflow. But Tomboy has some very interesting plugins which might be nice for org-mode as well.

As I said before, Tomboy is only an example here -- there are many other D-Bus services available ('dbus-list-activatable-names') And D-Bus services are introspectable - you can search through them, and retrieve information about the interfaces they provide, as well as the methods and signatures. Again, the Emacs D-Bus infopages are quite useful.

Posted by djcb at 2:13 PM 5 comments
Labels:

2009年01月21日

emacs 23

As per January 2009, the current stable version of GNU/Emacs is 22. However, there is a development version 23 available from CVS. The development version should become the next stable version in the not-too-distant future. I've been using emacs 23 for more than one year now, and have found it very reliable.

I'll be discussing some of the Emacs 23 specific tricks in some future entries, here I will discuss a small number of visible ones. This does not even scratch the surface of what is new - it's just a little taster.

One of the biggest, user-visible changes in Emacs 23 is the support for anti-aliased fonts on X11. This means that the fonts will look much smoother -- and as noted, users feel more effective when using pretty technology. In this case, some pictures are probably in order; the two screenshots show emacs-22 versus emacs-23, using default settings. The difference is striking, to say the least.

Emacs also supports variable-width fonts, so you could use any TrueType (and some other) font. However, I prefer to use a fixed-width font; a nice one is the Inconsolata font (ttf-inconsolata in Ubuntu/Debian, inconsolata-fonts in Fedora).

Another interesting new feature is DBUS-support; D-Bus is an IPC system used on Linux/Unix to communicate between applications. Using D-Bus, Emacs now even has support for querying the network for ZeroConf-devices when you are using Avahi; for example, insert a list of all printers in the local network into the current buffer, you could do something like:

(require 'zeroconf)
(zeroconf-init)
(dolist (srv (zeroconf-list-services "_printer._tcp"))
 (insert (format "\nprinter: %s" (nth 2 srv))))
Of course, this is not so useful. But being able to use Zeroconf (and D-Bus) easily from within emacs enables all kinds of interesting hacks... to be continued.

A maybe-useful graphical gimmick is that you can now change the 'opacity' (non-transparency) of your emacs frame (window) if you're on MS-Windows, or on some X with compositing enabled (Compiz, metacity-with-compositing, ...).

(modify-frame-parameters (selected-frame) 
 `((alpha . 90)))
will make your frame (window) 90% opaque (ie., 10% transparant).

If you're very conservative, you should of course wait for the official release of the new emacs. If you are a bit more adventurous, I can definitely recommend it. I have not come across any bugs. Of course, your mileage may vary.

The easiest way to get emacs 23 is to get some prebuilt packages;

  • For Windows, Ian Eure's MacOS-packages (haven't tested those);
  • For Debian, you can get emacs-snapshot-packages from orebokech, which are update weekly;
  • For Ubuntu, there are emacs-snapshot-packages from Ubuntu-Elisp
I guess there must be similar packages for Fedora/Suse/... but I could only find some older packages from EmacsCvsAndFedora. That says more about my searching skill than anything else, I guess... You can however also compile the new emacs yourself; it's not too difficult and there are some instructions in EmacsWiki, but note that the page is partly outdated.

Final note: if you have to have some emacs-23 specific code in your .emacs, but you also need emacs-22, you can use some like:

(when (>= emacs-major-version 23)
 ;; do something only in emacs 23
 )
Posted by djcb at 9:27 PM 14 comments
Labels:
Subscribe to: Comments (Atom)
 

AltStyle によって変換されたページ (->オリジナル) /