## 2009-11-26

### emacs regex replace

On Nov 23, 5:41 am, m121212 wrote:
> Hi,
>
> I have a tricky problem that I'm not sure how to solve. I have a latex
> document with several figure environments that look like this:
>
> \begin{figure}
> \includegraphics{blah.ps}
> \end{figure}
>
> but need to look like this:
>
> \begin{figure}
> \begin{center} \includegraphics{blah.ps} \end{center}
> \end{figure}
>
> Some of the figure environments already have this however, and I don't want
> to end up with something like this:
>
> \begin{figure}
> \begin{center}\begin{center} \includegraphics{blah.ps}
> \end{center}\end{center}
> \end{figure}

This page answers your question exactly:

• Elisp Lesson: Repeated Find Replace
http://xahlee.org/emacs/elisp_repeat_replace.html

if you prefer emacs to ask you for each case, perhaps just to be sure your regex didn't find a bad match, see:

• Lisp Lesson: Regex Replace with a Function
http://xahlee.org/emacs/lisp_regex_replace_func.html

> Any ideas? Also, is there a way Emacs can just wrap any selection with
> custom, predefined tags?

(defun wrap-markup ()
"Insert a markup <b></b> around a region."
(interactive)
(goto-char (region-end)) (insert "</b>")
(goto-char (region-beginning)) (insert "<b>")
)

the above is from a collection of simple elisp examples at

• Emacs Lisp Examples
http://xahlee.org/emacs/elisp_examples.html

Xah
∑ http://xahlee.org/

### automation may not be easy (emacs)

On Nov 23, 4:02 pm, Matthew Dempsky wrote:
> Whenever I'm composing a changelog entry for vc-mode, I like to be
> able to view the corresponding diff. Currently, after I use 'C-x v v'
> to create the *VC-Log* buffer, I immediately press 'C-c C-d' to open
> the *VC-Diff* buffer. Then after entering my changelog entry and
> committing with 'C-c C-c', I always immediately close the *VC-Diff*
> buffer.
>
> I was wondering about ways to automate the extra steps. I'd
> appreciate any concrete suggestions on how I could achieve this
> behavior.
>
> Thanks.

i've never used vc-mode... don't know what it is except just reading about it's inline doc now. I suppose many others here haven't either so maybe you are not getting answer...

you could define easy shortcut keys, for example, f4 for going log buffer, f5 for going to diff buffer, f6 for closing the current buffer... (if you don't know how to do that, see: http://xahlee.org/emacs/keyboard_shortcuts.html )

might involve a bit elisp code since the buffer you want may depend on the current buffer's name. But to give concrete elisp code i need to know...

ohterwise, if you can explain more abtractly what you need without reader having knowledge of vc-mode... i could help more. For example, in what exact situation in tech terms you want what action to be taken. (if, your need actually do have such unique description. Because sometimes something seems simple on the surface but there's a lot implicit assumptions that makes automation hard or impossible.)

Xah
∑ http://xahlee.org/

## 2009-11-10

### how windows set keyboard shortcuts

when i upgraded my PowerShell installation on my Vista, the download page forced me to install Microsoft File Transfer Manager (FTM) because the download only comes in that format.

Now, if i press Ctrl+Alt+f, the FTM starts up. How to disable this shortcut? I need this key in emacs.

I looked in registry HKEY_CURRENT_USER/Software/Microsoft, but couldn't find it.

Thanks.

Xah
∑ http://xahlee.org/

### set emacs's window size on init

i have, at the end of my .emacs this code:

; set frame size to 100x58 chars.
(set-frame-size (selected-frame) 100 58)

however, it doesn't work.
But eval-region the code itself would work.

Anyone know why's that?

Thanks.

Xah
∑ http://xahlee.org/

## 2009-11-04

### emacs decompress gzip file in dired won't work

gzip problem

when using emacs on Windows, when in dired, when i press Z on a file that's gzip compressed, emacs tells me:
'gunzip' is not recognized as an internal or external command,

the problem is apparently that emacs won't recognize the gunzip shell script without the exe suffix. (the gunzip is in the same dir as gzip.exe) But if i rename gunzip to gunzip.exe, but Windows complain that the file is not a exe format.

How to solve this problem?

extra detail:

when i do
(executable-find "gzip")
emacs says
"c:/cygwin/bin/gzip.exe"

and
(executable-find "gunzip")
says
nil.

the gunzip exists at
c:/cygwin/bin/gunzip
which is a shell script.

Xah
∑ http://xahlee.org/

this is reported as emacs bug
http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=4867

So far, i haven't been able to get this to work, after taking in all the suggestions in this thread.

Here's a more full report.

Suppose in dired you have a a file named x.txt.gz, and you move your cursor to it, then press Z. Emacs will ask you “Compress or uncompress x.txt.gz? (y or n)”. Answer y should uncompress the file, as the expected behavior.

I have “gunzip” installed by cygwin at “C:\cygwin\bin”. In emacs, when you do a “shell-command” then “which gunzip”, the output is “/usr/bin/gunzip”. This means, emacs can find the file.

The content of that file is:
«
#!/bin/sh
PATH=${GZIP_BINDIR-'/usr/bin'}:$PATH
exec gzip -d "$@" » Here's the problem. When i do Z, i get this error: “apply: Searching for program: no such file or directory, gunzip”. This is odd and shouldn't happen, since the file is right there and emacs can find the file by “which gunzip”. if i rename the file to gunzip.bat, then i do Z in dired on the file, i get this error: « c:\Users\xah\web\xahlee_org\emacs>#!/bin/sh '#!' is not recognized as an internal or external command, operable program or batch file. c:\Users\xah\web\xahlee_org\emacs>PATH=${GZIP_BINDIR-'/usr/bin'}:$PATH c:\Users\xah\web\xahlee_org\emacs>exec gzip -d "$@"
'exec' is not recognized as an internal or external command,
operable program or batch file.
Failed to compressc:/Users/xah/web/xahlee_org/emacs/xxxx.txt.gz
»

So, apparantly, emacs can find the program now, but for some mixed reasons of Windows cmd.exe and cygwin bash and emacs, it seems to run it as win cmd.exe script and not bash. I suppose this is expected behavior.

if i rename the file to gunzip.sh, i get this error:

«apply: Searching for program: no such file or directory, gunzip»

the value of my exec-suffixes is
(".exe" ".com" ".bat" ".cmd" ".btm" "")
after changing it to
(".exe" ".com" ".bat" ".cmd" ".btm" ".sh" "")

still same error.

Renaming the file to gunzip.exe wont work because .exe files needs to be in certain format.

Note that also even if renaming to gunzip.bat or gunzip.sh worked for this emacs usage situation, that probably isn't a good solution because it will probably break cygwin, since in unix shell it is expected to be just “gunzip” not “gunzip.bat” or “gunzip.sh”. So, if renaming can work for emacs, possibly i'll just create it else where and put it in a different path...

am i missing something?

does Z in dired on a compressed file work for anyone in Windows?

Xah
∑ http://xahlee.org/

Found a solution. Create a file name gunzip.bat, with this content:

@echo off
gzip -d %1

thanks to Eli and others.

I filed a bug report to FSF on this. #4867. I think this should still considered a bug though. Considering it as a Windows OS problem isn't very helpful in solving this. I'm sure if similar problems happens in linux that's OS issue, people probably will not look at it as “Oh, it's OS issue, emacs doesn't need to deal with it”.

Xah
∑ http://xahlee.org/

## 2009-10-26

### PowerShell version number confusing

with Windows 7 coming out, i thought there's a later version of PowerShell, so i tried to upgrade.

After downloading (have to download File Transfer Manger first), then i type $PSVersionTable, i get: Name Value ---- ----- CLRVersion 2.0.50727.4200 BuildVersion 6.0.6002.18139 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1 but back in 2009-08-01, the output was: PS C:\Users\xah\web\powershell>$psversiontable

Name Value
---- -----
CLRVersion 2.0.50727.4016
BuildVersion 6.1.6949.0
PSVersion 2.0
PSCompatibleVersions {1.0, 2.0}

the download location and the new requirment of FTM is quite confusing. The method to find out the version number of PowerShell is also confusing...

Compare the BuildVersion. Did i just downgraded?

I downloaded from
http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx
on the top right link, which points to
https://connect.microsoft.com/windowsmanagement/Downloads
and requires FTM installed.

This is supposed to be a release candidate.

My previous version, downloaded around month July, is 2.0, CTP 2 i think, also from
http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx
but the download is a direct install, not requiring FTM.

Xah
∑ http://xahlee.org/

## 2009-10-18

### unicode in newsgroup posts

On Oct 17, 6:46 pm, dkco...@panix.com (David Combs) wrote:
> In article ,
> Xah Lee wrote:
>
> Please -- I know you love your nice control-chars your posts
> always include, but it sure makes it near IMPOSSIBLE for us
> to read, or especially to NICELY save, them.
>
> Suggestion:
>
> Each post you make, DOUBLE it: first part "your way", then
> a dashed line or lines, then again, but without that stuff
> in it. Just plain ascii, minus any within-line control-chars.
>
> (Presumably you take the trouble to write your posts, to think
> them through, etc, because you want us to READ them, to BENEFIT
> from them, perhaps to even SAVE them. Seems to me that it would
> thus be to YOUR benefit to make them as easy as possible to read,
> and likewise to save away, maybe even for OTHERS to read (attributed
> to you, of course).)
>
> Thanks for at least considering the above.

Hi David,

was it you who wrote me at least twice about this issue in the past in separate times?

If i didn't recall incorrectly, i never got any reasons what is the problem.

The "control chars" you mention, are unicode characters, and pretty standard ones, such as curly quotes and bullets.

I wrote all my posts using just emacs, and they show correctly in just about all web browsers from groups.google.com. There is no problem in copy and pasting them, nor can i imagine there any problem in saving them as file, in any of Windows, Mac, or linux. the encoding used is utf-8, default in mac, linuxes, and fully supported Windows.

unicode is charset in langs like xml, java... etc.

can you be explicit exactly what is the problem? is it some news reader that does not support unicode? i haven't tried, but it'd be a major shame if u telling me emacs+gnus or Mozilla's Thunderbird does not support unicode out of the box?

Xah
∑ http://xahlee.org/

## 2009-10-15

### how to add words in aspell with emacs

On Oct 15, 2:47 am, Water Lin wrote:
> Two more question about using Aspell with flyspell mode.
>
> The first question:
>
> When Aspell finds an incorrect word, it will mark the incorrect word
> with special underline and color. But there are also a lot of special
> words like Flyspell, Aspell etc. which are meaningful but incorrect.
>
> I want to let Flyspell to ignore these words. What's the command?

right click on the word, and there's a menu command to add the word to your personal dict.

aspell creates your personal words file by default at
~/.aspell.en.pws

you can add or delete words there directly.

to find out what keyboard shortcut or command is called when right click the menu item, you can use describe-key.

> The second question:
>
> After successfully installed Flyspell with Aspell, I find that the input
> speed of my keyboard is a little slow and panic. It seems that flyspeel
> will influence my input speed. What can I do with it?
>
> My solution is:
> -------
> I disable Flyspell mode, but after I finish the email edition, I
> will use M-x ispell-region to check my spell. Is it a good way?

this solution is what i use. In fact, i use speck-mode (look at emacswiki.org for it). In my experience, it's faster, more robust. It doesn't do spell checking as you type though. It's batch, but faster than flyspell-buffer...

------------

spell checking is a critical feature of text editors. Spell checking frustration with Emacs on the Windows OS is a frequently asked question here. (the installation, configuration, is a huge pain in the ass even for professional unix sys admins and longtime emacs users) The GNU Emacs people, for some political, social , philosophical, or technical reasons, do not or will not make emacs work out of box on the Windows platform (their perspective may differ than the way i expressed it here). This, in my opinion, is a major problem of advancing emacs.

For issues related to this, see:

• Emacs Does Not Support Viewing Images Files In Windows
http://xahlee.org/emacs/modernization_image_support.html

• Problems of Emacs Supporting Obsolete Systems
http://xahlee.org/emacs/emacs_supporting_DOS.html

Xah
∑ http://xahlee.org/

## 2009-10-14

### run current file

On Oct 12, 3:39 am, wdysun wrote:
> Hello dears,
>
> suppose I have a script in /bin, let us assume it is called mytex. Suppose I
> am editing a file called filename.tex.
>
> If I run the following command from the console:
>
> \$ mytex filename
>
> this will do several things (tex the filename with several options, then
> convert the dvi to pdf and it deletes all aux files I don't need).
>
> There is a way to launch the script from emacs or even to build a function
> so that I can run the command just with M - something?

have a look here:

• Elisp Lesson: Execute/Compile Current File
http://xahlee.org/emacs/elisp_run_current_file.html

excerpt:

(defun run-current-file ()
"Execute or compile the current file.
For example, if the current buffer is the file x.pl,
then it'll call “perl x.pl” in a shell.
The file can be php, perl, python, ruby, javascript, bash, ocaml, java.
File suffix is used to determine what program to run."
(interactive)
(let (ext-map fname suffix progName cmdStr)
(setq ext-map ; a keyed list of file suffix to comand-line program to run
'(
("php" . "php")
("pl" . "perl")
("py" . "python")
("rb" . "ruby")
("js" . "js")
("sh" . "bash")
("ml" . "ocaml")
("lsl" . "lslint")
("vbs" . "cscript")
("java" . "javac")
)
)
(setq fname (buffer-file-name))
(setq suffix (file-name-extension fname))
(setq progName (cdr (assoc suffix ext-map)))
(setq cmdStr (concat progName " \"" fname "\""))

(if (string-equal suffix "el")
(load-file fname)
(progn
(message "Running...")
(shell-command cmdStr)))
))

Xah
∑ http://xahlee.org/

## 2009-10-11

### elisp text processing: disable undo, etc

On Oct 10, 6:49 pm, Decebal wrote:
> I am doing a lot of work on a big buffer (65 MB). I understood that
> there is a possibility to disable the undo functionality. Something
> that is not used in batch-mode. So this could give a performance
> boost.
> How can I disable undo?
> Are there other things that could be usefull performance wise?

buffer-disable-undo

you find it by calling “elisp-index-search” with search word “undo”.

for batch processing, you want to disable undo, also turn off syntax coloring, possibly turn off auto save, auto back up, ...etc.

best do it with temp buffer

e.g.

(defun my-process-file (fpath)
"Process the file at path FPATH ..."
(let ()
;; create temp buffer without undo record.
;; first space in temp buff name is necessary
(set-buffer (get-buffer-create " myTemp"))
(insert-file-contents fpath nil nil nil t)

;; process it ...
;; (goto-char 0) ; move to begining of file's content
;; ...
;; (write-file fpath) ;; write back to the file

(kill-buffer " myTemp")))

or use with-temp-buffer or with-temp-file.

for more tips on using elisp as a text processing lang like perl, python, see:

• Text Processing with Emacs Lisp
http://xahlee.org/emacs/elisp_idioms_batch.html

Xah
∑ http://xahlee.org/

## 2009-10-06

### ergonomics and efficiency

On Oct 5, 2:39 am, Johan Andersson wrote:
> Xah Lee, You say this at your site: "This shortcut set is designed based on
> ergonomic principles". What about efficiency? I guess ergonomics and
> efficiency could be related. But not necessarily.

typically efficiency is part of the consideration of ergonomics.

See:
http://en.wikipedia.org/wiki/Ergonomics

Quote: «Ergonomics (or human factors) is the scientific discipline concerned with the understanding of interactions among humans and other elements of a system, and the profession that applies theory, principles, data and methods to design in order to optimize human well-being and overall system performance.»

Note the last few words: “... and overall system performance”.

Xah
∑ http://xahlee.org/

### trade off for better but uncommon

On Oct 5, 12:57 am, Johan Andersson wrote:
> Raven, looking at those movement keys, they are almost like Xah Lee's
> "ergonomic emacs keybindings".
>
> Xah Lee, looking through the dvorak lisp file you provided at your site, I
> think that I could really dig those bindings, with a few modifications.
> However, I was thinking about these bindings and the shell. How do you
> survive (if you use a shell outside of Emacs) that the shell C-a, C-e almost
> always means beginning and end of line? Of do you change them there aswell?

when you opt for something that's less conventional, such as dvorak layout, you trade for certain disadvantage... e.g. unable to touch-type at public library, inconvenient to have co-work type on your keyboard, some inconvenience when using some software, such as some gaming software that doesn't respect your OS wide layout setting, some inconvenience in using some hardware, such as those palm-sized mini-computer that comes with a hardware keyboard with qwerty printed on them and too small to be touch-typed even software mapped to dvorak... etc.

similarly, if you adopt the ErgoEmacs Keybinding for your emacs... you stop using the conventional emacs keybindings for bash... either you spend time to tweak your keybinding system wide, or spend time to tweak your shell's binding... or just switch memory when in shell as you do between different apps or OSes. etc. For me, i just use emacs default keybinding when i'm in shell... but 99% of the time i run shell inside emacs.

Xah
∑ http://xahlee.org/

On Oct 6, 10:20 am, "B. T. Raven" wrote:
> > when you opt for something that's less conventional, such as dvorak
> > layout, you trade for certain disadvantage... e.g. unable to touch-
> > type at public library, inconvenient to have co-work type on your
> > keyboard, some inconvenience when using some software, such as some
> > gaming software that doesn't respect your OS wide layout setting, some
> > inconvenience in using some hardware, such as those palm-sized mini-
> > computer that comes with a hardware keyboard with qwerty printed on
> > them and too small to be touch-typed even software mapped to dvorak...
> > etc.
>
> Blackberries are supposed to be thumbed anyway. Layout on such a
> miniscule keyboard isn't a touch typing issue since the method will
> always be essentially hunt and peck.

So, that means, when you use Blackberries, you have to thumb them, and when you thumb them, you have to face qwerty buttons. For a person who are used to Dvorak, that is a inconvenience, even though the person is not touch typing.

> Of course libraries should have a Dvorak keyboard option available with
> a one-click or one-keychord method of changing keyboards.

Library is a example of the thesis.

> In practice,
> at libraries, you're typing a few search terms or short commands so that
> two-fingered typing doesn't have to be endured for long.

many libraries in the US, in tech advanced cities anyway, such as the San Francisco Bay Area of California , have internet terminals that lets library users use for prolonged period of time. (when there are a lot people in waiting, typically 20 min or 30 min per person)

Again, library is just a example of the thesis.

For example, besides libraries, there are companies, any public terminal, public exhibitions, meuseums, ... etc. The point being, that if u chose dvorak layout, you encounter many inconveniences in lots of places and situations. Many of these situation are trivial, insignificant, can be worked around, but nevertheless, they are inconveniences and annoyances.

The more general point being, there is inconvenience when you choose something that is less common, even if superior. This applies to the dvorak layout users, as well as Mac users in the PC world, as well as Linux users in the PC world.

Xah wrote:
> > similarly, if you adopt the ErgoEmacs Keybinding for your emacs... you
> > stop using the conventional emacs keybindings for bash... either you
> > spend time to tweak your keybinding system wide, or spend time to
> > tweak your shell's binding... or just switch memory when in shell as
> > you do between different apps or OSes. etc. For me, i just use emacs
> > default keybinding when i'm in shell... but 99% of the time i run
> > shell inside emacs.

B T Raven wrote:
> In both Linux and w32 environments you have the same keyboard layout in
> Emacs, shell and in all other apps. You wouldn't expect to have Emacs
> keybindings outside of Emacs in either enviroment unless you explicitly
> set them up as shortcut keys on a per app basis, as in Firemacs.

not sure what is your point or what are you trying to say. Are these general remarks, or as counter argument to my previous post? As general remark, i don't think it is true or exact enough. For example, you said:

> In both Linux and w32 environments you have the same keyboard layout in
> Emacs, shell and in all other apps

Hum?? i assume w32 means Microsoft Windows? In Microsoft Windows, the general common keybinding, or common shortcuts for text editing related applications, certainly isn't like emacs. At best, we can say that emacs also support some of it.

In unixes, typically the bash shell supports *PARTS* of emacs's text editing shortcuts. If you are using other shell, they don't suppor emacs keyboard shortcuts for text editing by default. Some can be customived to, and i'm not sure they all can.

In linuxes, which i haven't used for about 7 years, i assume it is still similar to unixes in this context, as explained in above paragraph.

Xah
∑ http://xahlee.org/

## 2009-10-03

### Window's way to input unicode vs Emacs

Hi David & Fra,

on issue 34:
http://code.google.com/p/ergoemacs/issues/detail?id=34

it is about adopting Windows's UI for entering unicode by the unicode's code point using decimal or hex.
e.g. Hold down Alt then press 0 2 0 0 on the num pad, to insert È.

I don't think this is a good idea. Here's the reasons and some thoughts.

Emacs has a complete system to input unicode chars, and a much superior one.

• by name, with wildcard support. Call ucs-insert. It supports name completion with wildcard.
• by unicode's code point with hexadecimal. Call ucs-insert, then type a hex.

I'm not sure there's a way out of the box to input by decimal. But if needed, it can be implemented in 5 min.

These are emacs standard way to input unicode, and a much superior one than the Windows way with Alt and keypad.

The inputting unicode with code point is not much used by vast majority of emacs users or programers (say, probably 1% of all professional programer would use it). Because, it requires the user to be familiar with unicode code points, and have somehow memorized the number for the char, or on special situations where he is working with unicode and have reference to insert the char he needed (such as in i18n programing or web dev).

So, inputting unicode by code point is only used for special occasions. If user needs to input unicode by code point, emacs ucs-insert provides a superior way with familiar interface. Emacs also provides many more convenient ways for entering unicode or frequently used non-latin-alphabet based langs. (e.g. set input system to one of the iso ones or ucs, or with shortcut C-x 8 ‹ascii art char›)

Introducing Windows's Alt+ num keypad way also is a major incompatibility of the way keyboard shortcuts are used. The Windows way is not a key combination nor a key sequence. It somewhat is a sticky key system, yet requires the Alt be down at all subsequent keys...

if we were to improve, i think a much more needed regarding to inputing unicode is a app is a visual character palette... On Windows, it has charmap but it quite sucks compared to Mac...

• the Windows way is not used on Mac. (am not sure about linuxes)

• the Windows way is dependent on code page...

some references:

• http://en.wikipedia.org/wiki/Windows_Alt_keycodes

• http://en.wikipedia.org/wiki/Charmap

• http://en.wikipedia.org/wiki/Windows_Alt_keycodes (there are some problems discussed there too)

• OS X's Character Palette (a much better analog to Windows's charmap) http://images.google.com/images?hl=en&source=hp&q=mac%20character%20palette&um=1&ie=UTF-8&sa=N&tab=wi

• OS X's keyboard viewer. http://images.google.com/images?hl=en&um=1&sa=1&q=mac+keyboard+viewer&aq=f&oq=&aqi=&start=0

• Emacs and Unicode Tips (discusses many of the ways to input unicode in emacs)
http://xahlee.org/emacs/emacs_n_unicode.html

• How To Create Your Own Keybinding In Mac OS X
http://xahlee.org/emacs/osx_keybinding.html
(shows screenshot of the Keyboard Viewer, and how to create your own unicode input layout on the Mac with its Keyboard Viewer)

Xah

### emacs and dvorak

i've been a professional qwerty typist hired for data entry for 1+ year in early 1990s.

I've been a dvorak touch typist since ~1993.

Started to use emacs, and daily, since 1998.

So, my emacs experience is all dvorak, and it's all good.

if you are thinking some sort of dvorak for typing and qwerty for hotkeys, don't do that.

there are quite a few pages about dvorak and emacs... how much time did you google?

if you want to try dvorak, just switch to the layout in your OS, and use emacs as is. That's the best way.

a lot people uses dvorak with emacs too... too lazy to cite them here. You can find them on blogs...etc. Try to spend a hour web search, you'll find probably more info or blogs, comments, etc that will take more than 4 hours to read, at least.

i have written quite a lot on the subject myself... you can read:

• Xah's Emacs Tutorial
http://xahlee.org/emacs/emacs.html

• All About Keyboards, Keyboard Layouts, Shortcuts, Macros
http://xahlee.org/Periodic_dosage_dir/keyboarding.html

Xah
∑ http://xahlee.org/

On Oct 3, 7:58 am, Johan Andersson wrote:
> Hi!
>
> I've been thinking for a while about testing Dvorak in Emacs (or Svorak for
> me since I'm from Sweden). Before I started I out, I googled a bit about
> "emacs dvorak", but to my suprise got really few hits about this. So I
> thought I'd ask here.
>
> First off I found out that you could do *C-\ english-dvorak RET*, which
> would activate Dvorak but still keep the the Emacs keybindings (So that you
> don't have to type C-l to go to the previous line). But that does not help
> me all the way, since I want to use Svorak. And by only switching the Xorg
> keyboard layout to Svorak, I'd still have to somehow remap all keybindings
> in Emacs.
>
> So the question is basically: How do I get Svorak working in Emacs? And do
> any of you even use Dvorak at all? I mean Emacs users often use Emacs
> because you can do things really fast, so I tought that many Emacs users
> would use Dvorak.
>
> Thanks!

## 2009-10-02

### finding the syntax to define shortcuts in emacs

On Oct 1, 12:06 pm, quodlibetor wrote:
> I would really like to bind C-).
>
> I've tried: (all of the following with both local- and global- set
> key)
>
> (local-set-key "\C-)" 'foo) ;error, invalid modifier in string
> "\C-\S-0" ;same
> [C-)] ;unbalanced parenthesis.
> [C-S-0] ; no error, but doesn't work
> [C-(kbd (self-insert-command ")")] ;totally borked
> [C-(kbd ")")] ; doesn't error, but really weird result
>
> etc, i can't remember.
>
> I tried entering into edmacro-mode to figure it out, and it hasn't
> helped me.
>
> Any tips seriously welcome.

The issue about emacs's syntax for defining shortcuts is a frequently asked confusion. Part of it has to do with emacs's keybinding syntax's and emacs lisp's historical baggage.

If you just want a working syntax, the solution is quite symbol.

Press Ctrl+h k (calling describe-key), then type what you want. For example, if you type “Ctrl+Shift+0” (which is “Ctrl+)” in us keyboard layout), then you'll get this message:

C-) is undefined

which means, the correct syntax is: “(kbd "C-)")”.

This tip is given at

• How to Define Keyboard Shortcuts in Emacs
http://xahlee.org/emacs/keyboard_shortcuts.html

---------------------------------

A separate issue, is that there's inconsistency for the kbd function's syntax when the key combo involves Shift.

Here's a except from the above article:

****************
Note: A keypress-combination such as “Meta+Shift+2” can also be considered as “Meta+@”. So, in emacs, you might be thinking that both of these code: “(kbd "M-S-2")” and “(kbd "M-@")” will work. Actually, only the latter will work.

When writing a keybinding definition, for a key combination that involves “Meta+Shift+‹key›”, you must use a version without the shift key if possible. For keybinding involving “Ctrl+Shift+‹letter›”, you must use the "-S". Examples:
GOOD BAD Keystroke
(kbd "M-A") (kbd "M-S-a") Meta+Shift+a
(kbd "M-@") (kbd "M-S-2") Meta+Shift+2
(kbd "M-:") (kbd "M-S-;") Meta+Shift+;
(kbd "C-S-a") (kbd "C-A") Ctrl+Shift+a

A easy way to find out the proper syntax, is to call “Alt+x describe-key”, then type the keystroke.

Note also, that keys involving “Ctrl+Shift+‹key›” cannot be distinguished from “Ctrl+‹key›” when emacs runs in a text terminal (i.e. telnet/ssh). So, this means best to avoid any binding with both Control and Shift.
****************

I filed a bug report on this, but i think it didn't come to any result.

http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=1111

(i'm pretty sure this particular inconsistency is in part of the thread bug#1111... but the website shows lots of spam now. Possibly it is in another bug report but don't have time to hunt it down at the moment. In particular, i remember Chong Yidong closed it or put it on wishlist or something.)

For more notes related to keyboard shortcut notations, see:

• The Confusion of Emacs's Keystroke Representation
http://xahlee.org/emacs/keystroke_rep.html

• Emacs's M-‹key› Notation vs Alt+‹key› Notation
http://xahlee.org/emacs/modernization_meta_key.html

• A Short Survey Of Keyboard Shortcut Notation
http://xahlee.org/emacs/modernization_hotkey_notation.html

Xah
∑ http://xahlee.org/

### Haskell's new logo, and Social Illiteracy of Tech Geekers

Haskell has a new logo. A fantastic one. Beautiful. For creator, context, detail, see bottom of:

• A Lambda Logo Tour
http://xahlee.org/UnixResource_dir/lambda_logo.html

this is posted here because it relates to various computer software/language's logo, a subject discussed by me several times in the past years in comp.lang.lisp, comp.lang.scheme, comp.lang.python, as well discussed now and then in these communities often without my involvement.

for my criticism or comment on logos, typical response by these people are showcases of complete ignorance of social function of logos, and a complete iliteracy in visual design (that any art student learns in first year), usually coupled with a teen-age militant attitude. (usually, these tech geeker's mentality is like: “you are a fucking idiot... we don't need a logo. Logos are for kids and blood-sucking marketers.”)

Some of these tech geekers, are motherfucking aggresive, so that they would ban me, or call me as a troll, or call upon whatever rules to oust me (such as “off topicality”) , for any criticism on them. (if requested, i'll take some time to cite the exact url for numerous of these threads that happened in the past 5 years. My frustration in discussing logos happened in python, lojban, lisp communities. Note: not all people in these communities are idiotic about logos. Typically, it's just few of priest fuckheads (e.g. a newsgroup regular, or somewhat significant contributor of the particular community). This particularly happened in several threads in the lojban community where i criticized its logo during mid 2000s. (have a look at lojban's motherfucking idiotic logo here: http://en.wikipedia.org/wiki/Lojban ))

• The Purpose of Logos and Principles of Logo Design
http://xahlee.org/UnixResource_dir/logo_design.html

• Lisp Needs A Logo
http://xahlee.org/UnixResource_dir/writ/logo_lisp.html

----------------
computer language and software logo gallery:

• The Unix Pestilence
http://xahlee.org/UnixResource_dir/freebooks.html

• A Lambda Logo Tour
http://xahlee.org/UnixResource_dir/lambda_logo.html

• LISP Logo
http://xahlee.org/emacs/lisp_logo.html

• Qi Language Logo
http://xahlee.org/emacs/qi_logo.html

• Haskell Logo
http://xahlee.org/haskell/haskell-logo.html

• The Emacs Logo
http://xahlee.org/emacs/emacs_logo.html

• Xah's Java Logo
http://xahlee.org/java-a-day/java_logo.html

Xah
∑ http://xahlee.org/

### emacs: inserting numbers into a column of text

On Oct 2, 7:05 am, Benjamin wrote:
> I use keyboard macros fairly frequently, but I often run into a
> situation where I would like to increment a number in the macro, e.g.,
> if I start with:
>
> tmp tmp tmp tmp
>
> and I want to end with:
> tmp1
> tmp2
> tmp3
> tmp4
>
> I know how to create the macro where it would result in:
> tmp1
> tmp1
> tmp1
> tmp1
>
> Is there a way to make the number increment each time the macro is
> executed?
> Otherwise I am forced to step down through each line and manually put
> the numbers in 1, 2, 3, 4, ...
> Naturally this is a greatly shortened example for illustration
> purposes, and often the incrementing takes place within a longer
> statement e.g., tmp(:,1) = function(x,y). My interest here is how to
> increment or decrement the number in a more automatic fashion.
>
> I don't mind doing something other than macros, or even external
> commands (perl/sed/awk, etc.)
> to assist with this.

This is a frequently asked question in emacs communities.

Different people has different solution. For me, i wrote a function to do it. I documented it in this page:

• Emacs Lisp Examples
http://xahlee.org/emacs/elisp_examples.html

The following is excerpt:
------------------------------------
Sometimes, you need to insert a vertical column of sequential integers into a block of text, like this:

do this x times
do this x times
do this x times
...

where the “x” should be 1, 2, 3, ... The following code does it.

(defun insert-counter-column (n)
"Insert a sequence of integers vertically.
Example:
do this 1 times
do this 2 times
do this 3 times
...

If there are not enough existing lines after the cursor
when this function is called, it aborts at the last line.

See also: kill-rectangle' and string-rectangle'."
(interactive "nEnter the max integer: ")
(let ((i 1) colpos)
(setq colpos (- (point) (point-at-bol)))
(while (<= i n)
(insert (number-to-string i))
(next-line) (beginning-of-line) (forward-char colpos)
(setq i (1+ i))
)))

--------------------------------------------------

Note: if you are a perl programer (or python, ruby, etc), you can easily write a function in your lang and have a emacs wrapper calling it. So that, you select you text, press a hotkey, and emacs call your script, feed it the current selection, and return the output replacing the current text selection.

This might be easier for many people.

• Elisp Wrapper For Perl Scripts
http://xahlee.org/emacs/elisp_perl_wrapper.html

Xah
∑ http://xahlee.org/

## 2009-09-17

### make powershell script a icon to launch?

Hi, is it possible to make a PowerShell script that can be double clicked to run?

I like to have a icon that executes this

& "C:\Program Files (x86)\ErgoEmacs\bin\emacs.exe" -Q --load=~\ErgoEmacs_Source\ergoemacs\ergoemacs\init.el --load=~\.emacs

i tried to save it as a file run_ergoemacs.ps1 but double click only opened the file in a text editor.

Thanks.

Xah
∑ http://xahlee.org/

## 2009-09-13

### keyboard shortcut notations

On Sep 13, 7:32 am, Francesco Biccari wrote:
> Hi David,
>
> to me, you are right.
> This notation is the most common in Windows applications (and I think
> also in other OS's) and it is less ambiguos than other ones.

I agree with should go with for example Ctrl+N, though i do have a little personal gripe... which i never thought in detail but anyway here it is.

With keys involving shift key, in my mind i always thought it should be
Ctrl+n and Ctrl+Shift+n, for the none-shifted and shifted version...

The difference between “my” model and the Windows model is that, in “my” model, keys are treated as characters/symbol/glyphs that makes up text, and users press keys on the keyboard to enter these characters. Emacs uses interpretation for its keyboard shortcut notation too) In Windows notation, keys are more thought of as keys on the keyboard hardware. This model is actually more sensible.

In the docs i wrote i always used “my” model, but never really seriously decided if it is better.

Both model do have some problems. In both “my” model and Windows's model, the notation for pressing all keys Ctrl and Shift and 1, has two notations: Ctrl+Shift+1 and Ctrl+@, but also Ctrl+Shift+@.

For example, the key combo to increase font size is pressing at the same time Control and Shift and Plus. In Windows Firefox, it is shown as Ctrl++. However, it really should be Ctrl+Shift+=. (just noticed, that in IE, it actually uses this notation “Ctrl +”, which shows that the IE people are willing to break notational consistency for ease of understanding)

This problem occur because of the fact that some keys are used for more than one glyph with the Shift down (e.g. 1 and !, 2 and @, 3 and # etc.). Basically, the result is that there is no one-to-one correspondence with key presses and the notation.

This problem gets worse with different keyboard layouts, because not all layouts have the same Shifted symbols. For example, i looked at the Spanish Spain layout, according to Wikipedia http://en.wikipedia.org/wiki/Keyboard_layout#Spanish_.28Spain.29.2C_aka_Spanish_.28International_sort.29 A key combination of Ctrl and &, would be: Ctrl+Shift+6 and Ctrl+&. But in US keyboard, it would be Ctrl+Shift+7 and Ctrl+&. (From this example, we can see a slight advantage of interpreting the notation as characters to type, instead of keys on keyboard. Because if we treat the notation as chars to type, then Ctrl and & would just be that only, not Ctrl+Shift+7 or Ctrl+Shift+6 depending on layout. Again, this is what emacs do, but again, emacs is “better” only because it too lazy to deal with keyboard and layout complexity. Keyboard notation really should deal with keys on the hardware as human pressing buttons, not as typing text.)

Btw, it is also worth to mention that Apple's OS X, does not use the plus sign for its keyboard notation... For example, in Firefox for the Mac, to zoom in, the notation on the menu is shown as: “⌘+”, which means holding down the Command key and press “+”. The Apple model is arguably more elegant

(was hoping to find some screenshots or do one myself... to lazy.
however, i did check Wikipedia,
http://en.wikipedia.org/wiki/Keyboard_shortcuts
but it didn't discuss Apple's notation.
)

I would be interested to know what are the notation shown in menus in Linux Gnome and KDE. (am guessing they follow Windows, but would like confirmation)

Anyway, all the above is just personal philosophizing. For ErgoEmacs, i think using Windows notation will be good.

Xah
∑ http://xahlee.org/

## 2009-09-12

### elisp: pulling code out of custom-set-faces

i have in my emacs init file these code:

(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(completions-common-part ((t (:inherit default :foreground "red"))))
'(pp^L-highlight ((((type x w32 mac graphic) (class color)) (:underline "maroon"))))
'(show-paren-match ((((class color) (background light)) (:background "azure2")))))

how to pull the code into a normal elisp code?

for example, in custom-set-variables

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(abbrev-mode t)
'(ange-ftp-try-passive-mode nil)
'(auto-save-default nil)
...
)

i can pull them out by replacing each line with the form:

(setq abbrev-mode t)

Thanks.

Xah
∑ http://xahlee.org/

## 2009-09-11

### emacs eshell quoting bug on -exec rm {} \;

this is probably a bug.

when running eshell in Windows, i do

c:\Users\xah\web>find -name "*el" -exec rm {} \;
find -name "*el" -exec rm {} \;
find: missing argument to -exec'

it turns out, one needs to quote the ending semicolon.

This does not work:
find -name "*el" -exec rm {} \\;

This works:
find -name "*el" -exec rm {} ';'

It appears to me, this seems to be a bug, since
-exec rm {} \;
is a standard idiom in shells, and no reason that shouldn't work.

Xah
∑ http://xahlee.org/

## 2009-09-06

### ErgoEmacs history

On Sat, Sep 5, 2009 at 2:19 PM, biccari wrote:
> > 1. Why don't you delete the Emacs2010 and ergoemacs keybindings
> > project and create a single Google page ErgoEmacs?
> > I think that now the situation is a bit confusing.

On Sat, Sep 5, 2009 at 11:36 PM, David Capello wrote:
> I think the same. I suggest that we should remove Emacs2010 and
> stay just with the already created "ergoemacs" google project (anyway
> I don't know if it is easy/possible to move all issues from emacs2010
> to ergoemacs, and we will lost SVN history (anyway it could be
> better to do it now that the respository is small)).

as far as i know, google code doesn't let you rename project. I think last i read you have to ask them to do it for you.

ideally, i'd like to rename emacs2010 to ErgoEmacs, and the “ergoemacs” to ErgoEmacs Keybindings.

Perhaps i'll have to post a request to google. A possible tech complexity is that we are renaming to existing names (i.e. emacs2010 → ergoemacs). So, i hope if we do this, there'd be no screwup. But in any case, the code base is small as David said. At worse, starting over new project from scratch is no problem.

I think we are kinda small now. I'm guessing there are maybe few hundred of ergoemacs keybinding users at most, and probably less than 5 who actually seriously use or looked at the code for ErgoEmacs (emacs2010).

My sense is that we are at early stage and can wait a bit... e.g. from my experience, lots of other projects that eventually became successful has to be renamed for legal reason or otherwise. (lindows, firefox, many others ...)

> Xah has the last word.

wee! :)

> > 2. At the moment your target are the Windows and Mac users.
> > Why don't you write a very small page where you suggest the best emacs
> > distribution (one of the EmacsW32 package for Windows or just GNU
> > Emacs? Aquamacs for Mac?) and put the instructions to install
> > ErgoEmacs over these distributions?

> That is a good idea. A wiki page "How to use ErgoEmacs with
> GNU Emacs" for advanced (current emacs) users. Anyway that
> tutorial should not be necessary to be read by any future ErgoEmacs
> user (when the installer is done).

> Maybe we need two pages:
> 1) How to install ergoemacs keybindings
> 2) How to convert your GNU Emacs to ErgoEmacs

i think (1) is already there. For (2), i hope we can have a ready-to-use binary soon.

Following is some more explanations.

Ideally, i'd like to see one simple page of just maybe 2 paragraphs of text, then a download button, for users to download this editor for Windows and Mac. (as binary of course) And, without any philosophies, emacs history, why another emacs, which choice you should make, etc. Basically, look at any mainstream successful software e.g. google chrome, firefox, opera, Visual Studio... without the “hacker community”'s extra culture to be able to make sense out of it.

For emacsW32 and almost all emacs distro out there (including the other major emacs distro for the Mac, the Carbon Emacs), it's trivial to install the ergoemacs keybindings.
(http://code.google.com/p/ergoemacs/)
for any who sees this page, they can get it to run in 5 minutes without problems. (otherwise it's a major bug)

The only exception is the Aquamacs Emacs on the Mac. Aquamacs is exception because it is in a world by itself (lol). It is designed to be a complete Mac-like application as much as possible. So, all emacs ways are gone. It is not easy to customize it for a typical emacs users, because its own customization is rather radical and large. (with files opening in its own windows, tabbed gui, lots other pop up gui, etc.) Basically, on the mac, there are 2 major distros. Aquamacs and Carbon emacs. Aquamacs is mostly for those who never used emacs before, and for those who have used emacs or came from unix, they usually use Carbon emacs. One can, of course, always customize emacs to whatever if he has enough time.

Aquamacs is highly successful however, as a editor, because it grabbed all the “normal” people (mostly academics/students, and non “hackers” and non unixers) who simply needed to use a editor. (most of its users are LaTeX users)

Aquamacs is not a good mix with ergoemacs keybindings, due to the fact that Mac uses the Cmd key for standard shortcuts. Since Aquamacs is meant to be a Mac application, so it fully respect that. This means, Ergoemacs Keybindings won't have the easy Cmd key for shortcuts. That basically throws off the purpose of ergonomics in ergoemacs. (the Mac's Cmd key is analogous to the Alt key on PC keyboards with respect to position)

> ErgoEmacs over these distributions?
> Now some informations are reported in the DeveloperIntro page but I
> think a simple page for the essential informations is a good thing.

this project for much of this year is just my own... started as frustration with the emacs people and my rants and own customizations. I figured it might be useful to put them together, and eventually thought might as well start a project. For much of this year there's just this emacs2 zip file you can download that's pretty much my own customizations. It should work with any emacs distro. (but without much quality checking) David helped a lot since he joined recently and helped to start to build a binary and made the ergoemacs into a minor mode.

For now, the emacs2 dir package is in a flux but should still work... again, we hope to get the binary out, which is the real goal.

Thanks a lot for your suggestions. It's always useful to get feedback.

Xah
∑ http://xahlee.org/

## 2009-09-05

### hotkey to enable/disable a AutoHotKey set

how can i create a hotkey that disable/enable a ahk script?

i can enable by

F4::Run c:/Users/xah/Documents/autohotkey/xah_hotkeys.ahk

but how to disable? (or, suspend/re-run)

Sometimes, in playing Second Life, i want to turn my general hotkeys off so i can use the game's function keys becomes available.

thanks.

Xah
∑ http://xahlee.org/

## 2009-09-03

### emacs truncate/line-wrap documentation problem

There's this variable truncate-partial-width-windows in emacs 23.1.

I think it's documentation is not very clear. I read the doc carefully, together with associated var such as word-wrap and truncate-lines. However, i cannot find out what exactly this variable do or its effects, after spending about 30 min setting various combination of values to these variables and or adjusting my frame width.

following is particular detail on why i didn't find it clear.
--------------------------------
The doc reads this:

> Non-nil means truncate lines in windows with less than the frame width.

this seems to be that this var only has effect when its val is less than frame width. So i set it to 30.

> For an integer value, truncate lines in each window with less than the
> full frame width, provided the window width is less than that integer;
> otherwise, respect the value of truncate-lines'.

I don't see any effect. It is not clear to me what this clause means: “truncate lines in each window with less than the full frame width”. It's not clear pratically, and it's ambiguous. Does the “with less than” being a codition where this takes effect, or does it mean it is the effect of this var? Also, the emacs tradition of using “truncate lines” can probably be improved. Usually, i understand it to mean “let long lines run off the right frame width”. It does not actually _truncate_ lines. In most of today's editors, similar feature is usually called “no word wrap” or “no line wrap”. This seems much more clear to me. So, in conjunction with this report on doc issue of truncate-partial-width-windows, perhaps emacs doc would consider change the wording of “truncate” in related documentation about line wrapping.

In any case, i cannot understand what this paragraph means.

> For any other non-nil value, truncate lines in all windows with
> less than the full frame width.

> A value of nil means to respect the value of truncate-lines'.

> If word-wrap' is enabled, you might want to reduce this.

In short, i tried to set this to 30 or 150. 30 is less than my frame width, and 150 is more. And tried to turn on off or set to other value the other mentioned vars, but i can't see the effect.

Thanks.

Xah
∑ http://xahlee.org/

http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=4334

Thanks Eli & Stefan on explaining this.

How about something like the following?

-----------------------
Documentation:
A value n sets the display to show only the first n characters per line.

This variable applies only when you have vertically split windows, and
when window width is less or equal to n.

You can customize this variable.

This variable was introduced, or its default value was changed, in
version 23.1 of Emacs.
-----------------------

Note that i removed the line “If word-wrap' is enabled, you might
want to reduce this.”. I don't see that line appropriate, nor as
sensible suggestion. My gut feelings i'd rather want slightly larger
value of n if word-wrap is enabled.

it's not clear to me what happens when the value is something other than positive integer and is not nil. The original doc seems to suggest that has particular behavior...

Thanks.

Xah
∑ http://xahlee.org/

## 2009-09-02

### coloring text phrase in emacs

i would like to highlight some phrases when a file is opened.

So, i thought i put this in the first line:

-*- eval-expression: (hi-lock-face-phrase-buffer "me:" 'red ) -*-

however, the proper syntax for hi-lock-face-phrase-buffer seems to be:

(hi-lock-face-phrase-buffer "me:"
(defface myface
'((((background dark)) (:background "red" :foreground "black"))
(t (:background "red")))
"reddit"
)
)

can it be simpler? I just need to color the text and background.

i have other people's names i need to color red, blue.

Thanks.

Xah
∑ http://xahlee.org/

### hard coded formatting mentality

On Sep 1, 8:21 pm, Allan Gottlieb <gottl...@nyu.edu> wrote:
> (I am using emacs 23.1)
> Start with emacs -Q and a buffer in fundamental mode
>
> Consider a line wider than the frame, for example
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> which exceeds an 80 column frame.
> Now assume you have a short line say
> yyyy
> followed by the above long line, i.e.
> yyyy
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> So far so good. Now indent the long line with say one space.
> If visual-line-mode is OFF, I see what I expect, the long line is
> preceded by one space.
>
> But with visual-line-mode ON, a blank line appears on the screen between
> the short and long lines, i.e. the long line (with only one word) was
> wrapped.
> This behavior seems wrong. I am getting burned in the following case
> among others with html
>
> <ol>
> <li>
> <a
> href="a-looong-url-that-naturally-contains-no-blanks">
> go here
> </a>
>
> When the looog-url exceeds the line length a blank line appears
> after the <a
>
> I realize the blank line is not in the file so the browser is not
> affected, but I find a plus of html to be that it reads well in emacs
> even when not formatted (by say w3m).
>
> Am I correct in viewing this as a bug? If so I will file a bug report.

it's not a bug. It's a natural behavior of smart word wrapping. Try that in any word processor, you see the same behavior.

The problem is that you have this un-natural long string, those 80 or so x. Not human language or computer lang have such long string as words.

for plain text, sure that happens, originated in 1980s as a hack of using ASCII pict to emulate a horizontal line. i.e. in html it's <hr>. Such a hack is less and less used today. If you must use it, word wrap (aka emacs's visual-line-mode) is not suitable.

all this has to to with physical formatting, a mindset particularly started by unix idiots. For references, see:

• A Simple Lisp Code Formatter
http://xahlee.org/emacs/lisp_formatter.html

• A Text Editor Feature: Extend Selection By Semantic Unit
http://xahlee.org/emacs/syntax_tree_walk.html

• The Harm of Hard-wrapping Lines
http://xahlee.org/UnixResource_dir/writ/hard-wrap.html

• Tabs versus Spaces in Source Code
http://xahlee.org/UnixResource_dir/writ/tabs_vs_spaces.html

• Plain-Text Email Fetish
http://xahlee.org/UnixResource_dir/writ/plain_text.html

• A Text Editor Feature: Extend Selection By Semantic Unit
http://xahlee.org/emacs/syntax_tree_walk.html

• Fundamental Problems of Lisp
http://xahlee.org/UnixResource_dir/writ/lisp_problems.html

Xah
∑ http://xahlee.org/

someone wrote: False!

I tried in Notepad, Notepad++, Wordpad, and on Mac: TextEdit, TextWrangler, XCode. These are the top major editors in Windows and Mac.

All behavior is as i described. I wasted me 15 minutes on this now. Fuck.

Tried Eclipse and NetBeans, but can't findout how to turn on wrap lines in them.

Xah
∑ http://xahlee.org/

### AutoHotKey !F4 means pressing Alt first or together?

in this example, where i tried to define a special case to close Microsoft Mail indiviual mail window.

Numpad0::
IfWinActive ahk_class ATH_Note
{
Send !F4 ; close window
}
else
{
Send ^w ; close window
}
return

why would !F4 not work? Normally, pressing Ctrl+F4 would close the window. But it activates the menu instead (apparantly behaving as if Alt is pressed first, followed by F4, which Windows Mail ignores). ( ! c works though).

my question is, when i have syntax like !F4, does that always mean pressing Alt, release, then F4? Whats the syntaxt for pressing Alt and F4 together at the same time?

Thanks.

Xah ∑ http://xahlee.org/ ☄

## 2009-09-01

### powershell's directory code? d-r--, d---hs etc

in PowerShell, when i do a dir, i get for example:

d-r-- 9/1/2009 11:16 AM Contacts
d-r-- 7/29/2009 8:50 PM Desktop
d-r-- 8/31/2009 9:28 PM Documents
d-r-- 9/1/2009 6:08 AM Downloads
d---- 8/28/2009 2:11 PM ErgoEmacs_Source
d-r-- 5/23/2009 9:56 PM Favorites
d-r-- 5/23/2009 7:23 PM Links
d---- 8/5/2009 3:40 PM Mail
d---- 5/25/2009 10:31 AM Movies
d-r-- 6/26/2009 4:54 PM Music

is there a page that explains all the code "d-r--"?

thanks.

Xah
∑ http://xahlee.org/

## 2009-08-29

### setting emacs font and the pain

On Aug 28, 5:20 pm, "Drew Adams" wrote:
> > How do i set a font for the current frame?
>
> M-x icicle-font S-TAB
>
> Choose any available font, using completion. Use M-SPC', if you want to match
> different font parts separately (taking the intersection).
>
> > What i want is a toggle-font code so that i can press a key and have
> > the font set to either a monospaced or variable-spaced one, and just
> > for the current frame. More specifically: what's the elisp function
> > that makes the current frame use Courier New? (i'll also need to
> > know the full string or whatever that emacs uses for what Windows
> > calls the Courier New font.)
>
> (set-frame-parameter nil 'font "-*-Courier
> New-normal-r-*-*-14-112-96-96-c-*-iso8859-1")
>
> or whatever font you want.
>
> M-: (frame-parameters) is your friend.

Thanks Drew & Florian.

Spent another 1 hour on this, didn't want to go further at this moment but wanted to report some findings and reply.

finally was able to get something useful:

(defun cycle-font ()
"Change font in current frame, cycling thru a predefined set of fonts."
(interactive)
(if (not (eq last-command this-command))
(progn
(set-frame-parameter nil 'font "-*-Courier New-normal-r-*-*-14-112-96-96-c-*-iso8859-1")
(put this-command 'state "2"))
(cond
((string= (get this-command 'state) "1")
(set-frame-parameter nil 'font "-*-Courier New-normal-r-*-*-13-112-96-96-c-*-iso8859-1") (put this-command 'state "2"))
((string= (get this-command 'state) "2" )
(set-frame-parameter nil 'font "-outline-Lucida Sans Unicode-normal-normal-normal-sans-13-*-*-*-p-*-iso8859-1") (put this-command 'state "3"))
((string= (get this-command 'state) "3")
(set-frame-parameter nil 'font "-outline-Code2000-normal-normal-normal-*-13-*-*-*-p-*-iso8859-1") (put this-command 'state "1"))
)
)
)

(global-set-key (kbd "") 'cycle-font)

This is for Windows Vista machine. Press a button it'll cycle among 3 fonts. Mostly for the purpose of switching between mono-width courier and variable-width lucida.

The Code2000 is there just for the occation of viewing some unicode. Code2000 is so bad that it renders ascii dash/hyphen as invisible if the font size is not huge.

Code2000 is not part of Windows Vista. You have to downloaded it, i wouldn't recommend it, just that i happened to already did and that seems to be the font containing the most unicode

the elisp dealing is also painful, or, much less than ideal. Here's a outline of my problem.

So, Drew showed me this

(set-frame-parameter nil 'font "-*-Courier New-normal-r-*-*-14-112-96-96-c-*-iso8859-1")

which is great. So, i wanted Lucida. So, logically, i replaced the courier name to lucida like this:

(set-frame-parameter nil 'font "-*-Lucida Sans Unicode-normal-r-*-*-14-112-96-96-c-*-iso8859-1")

but emacs spits out error. I didn't know what those 112, 96, 96 are, so i figured i replace them with asterisk. Tried a few variations, no go. After a while, i found this works:

(set-frame-parameter nil 'font "Lucida Sans Unicode")
(set-frame-parameter nil 'font "courier new")
(set-frame-parameter nil 'font "Fixedsys")
(set-frame-parameter nil 'font "FixedsysTTF")

but i do need to set size because the size spec is not equivalent among fonts. e.g. One font at size 14 will be too large/small for another font at 14.

So i need something like.:

(set-frame-parameter nil 'font "Lucida Sans Unicode" 'size 12)

after looking up some inline doc or elisp doc in few min, i can't find out what's the available parms for set-frame-parameter. But i did find this function:

(frame-parameters)

which gives out all the params/value pairs in a frame. So, after a while finding no easier way, i went thru the rather tedious process of using the menu to set a font, then run the frame-parameters and get the value of the font. So, i get the right font string spec for the fonts i want. e.g.

"-*-Courier New-normal-r-*-*-13-112-96-96-c-*-iso8859-1"
"-outline-Lucida Sans Unicode-normal-normal-normal-sans-13-*-*-*-p-*-iso8859-1"
"-outline-Code2000-normal-normal-normal-*-15-*-*-*-p-*-iso8859-1"
"-raster-Fixedsys-normal-normal-normal-mono-15-*-*-*-c-*-iso8859-1"
"-outline-FixedsysTTF-semi-bold-normal-normal-mono-16-*-*-*-c-*-iso8859-1"

btw, in my haphazard notes i found font-spec, e.g..

(font-spec :family "Unicode Symbols" :size 24)

which turns out not useful here.

now i got cycle-font, next job when i have time would be setting monospaced font whenever dired is opened or calendar (recently someone asked for that, which prob means lots others have the same question)... and also the job of getting all unicode to show...

---------------

ok a question. Is there a doc that list all the params of set-frame-parameter?

i've not attempted to read the elisp doc for the frame section or font/faces section in some cover-to-cover manner... well eventually i'll have to do that.

the cycle-font command above can be improved too... not happy with the state cycle code... hackish.

Xah
∑ http://xahlee.org/

## 2009-08-25

### setting default font for emacs

On Aug 25, 7:11 pm, Tom Roche wrote:
> summary:
>
> I'm running an emacs-23 and am wanting to set my default font for
> every frame in init.el. How to do so properly?
> ...

yeah, there's a better way.

pull the menu “Options‣Set Default Font”. Choose a font. Then pull “Options‣Save Options”. That should do it. However, on Windows, i noticed there's a bug that doesn't save the font. A work around is that, once you did the above, then type M-x customize. Then randomly choose something to customize. Then press Save for Future Sessions. That should save the font you've choosen. In particular, you should add something like the following in your emacs init file:

(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "honeydew" :foreground "SystemWindowText" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "outline" :family "Lucida Sans Unicode"))))
'(completions-common-part ((t (:inherit default :foreground "red"))))
'(pp^L-highlight ((((type x w32 mac graphic) (class color)) (:underline "maroon"))))
'(show-paren-match ((((class color) (background light)) (:background "azure2")))))

I am also interested in the raw elisp code to save the font or other face related things, without the custom-set-faces.

Given a (custome-set-faces ...) code, how do i pull things out and create the equivalent elisp code? setq certainly won't work.

Xah
∑ http://xahlee.org/

### emacs lisp data structure

On Aug 25, 7:22 am, Dirk80 wrote:
> Hi,
>
> sorry for this beginner question. But I'm very interested how you would
> represent the data structure of my example in elisp.
>
> Here my example:
> I want to implement a vocabulary trainer in elisp.
>
> I have units. A unit is consisting of lessons and lessons are consistng of
> sublessons. One sublesson is consisting of vocabularies. A vocabulary is
> consisting of an audio-file, picture file and a text.
>
> Here how I would do it in C:
>
> struct Vocabulary
> {
> char audio_file[255];
> char picture_file[255];
> char text[1000];
>
> };
>
> struct SubLesson
> {
> int nb_vocabularies;
> struct Vocabulary[1000];
>
> };
>
> struct Lesson
> {
> int nb_sub_lessons;
> struct SubLesson sub_lessons[10];
>
> };
>
> struct Unit
> {
> int nb_lessons;
> struct Lesson lessons[10];
>
> };
>
> struct UnitList
> {
> int nb_units;
> struct Unit units[8];
>
> };
>
> e.g. Unit 4, Lesson 7, Sublesson 2, Vocabulary 1, audio-file
> struct UnitList unit_list;
> unit_list.units[3].lessons[6].sub_lessons[1].vocabulary[0].audio_file =
> "hello.wav";
>
> Now to the details of using. Because I think this is important in elisp
> because of performance.
> This "UnitList" shall be initialised with content. During runtime it will
> never be changed.
>
> Thank you a lot in advance for your help
> Dirk

emacs lisp, pretty much like other scripting lang, has variously called arrays, lists, hash tables, ... etc., and the types be nested rather flexibly.

Specifically, emacs lisp has it its terminology: arrays, lists, associative lists, and hash tables. Their difference is primarily their algorithmic acess properties.

Arrays are written as e.g. “[3 "a", 8, 7, "something"]”, and it is fast to access random elements, but very slow to add or delete elements.

Lists are written as e.g. “(list 3 7 9 "some")” or “'(3 7 9 "some")”, underneath they are cons cells like this: (cons 3 (cons 7 (cons 9 (cons "some" nil)))).
Lists are fast to prepend, but slow if you need random access to elements in middle.

Associative lists are pretty much a list of cons pairs. Extra difference is that you have easy interface with key and value structure. You can query a data, query a value, get all keys, get all values etc.

Hash is interface wise just list of pairs, but implemnted in a different way (not as lists or cons), so that it's extremely fast to query any element. Typically used for largish pairs. (say, thousands) There is no syntax to build hash directly. You have to build them element by element. (this is a common complaint and a problem of lisp)

So, if you want your data structure in memory, you pretty much use a nested mix of one of the above. Exactly how you mix and nest them depends on your app. I suppose if you have data like audio files or large text, your values in your structure will just point to them. e.g. as file paths.

i noticed few years ago there are already a couple or more flash card or dictionary type of apps written in elisp. Might look around.

here's lisp basics:

• Emacs Lisp Basics
http://xahlee.org/emacs/elisp_basics.html

• Elisp Lesson: Hash Table
http://xahlee.org/emacs/elisp_hash_table.html

• Sequences Arrays Vectors - GNU Emacs Lisp Reference Manual
http://xahlee.org/elisp/Sequences-Arrays-Vectors.html

• Lists - GNU Emacs Lisp Reference Manual
http://xahlee.org/elisp/Lists.html

Here's a criticism of lisp's list problem.

• Fundamental Problems of Lisp
http://xahlee.org/UnixResource_dir/writ/lisp_problems.html

Xah
∑ http://xahlee.org/

### Windows AutoHotKey: closing the current tab or app

how can i create a hot key, so that, it'll either close a tab if there's a tab in the app, or close the app?

if i do Ctrl+w or Ctrl+F4, that closes tabs in browsers, but if i'm in say Windows Mail, Ctrl+w takes me to newsgroup subscription and Ctrl+F4 does nothing.

basically i want a simple key to close whatever i see, without needing to figure out it is Ctrl+w, Ctrl+F4, or Alt+F4.

Thanks.

Xah ∑ http://xahlee.org/

### emacs: deleting dir and all sub dir

On Aug 25, 1:37 am, Alain Muls wrote:
> Hi emacs users
>
> I installed trashcan.el and this works fine for deleteing files from
> dired, but deleting a directory (recursively) cannot be done. Is there a
> way around?

to delete dir, you need to set a built-in var.

Q: How to delete or copy a entire directory

A: Type “Alt+x customize-variable” then “dired-recursive-deletes”, then click on the Value Menu to make a choice. Then, click “Save for Future Sessions”, then “Finish”. Do the same with variable “dired-recursive-copies”.

;; allow dired to be able to delete or copy a whole dir.
(setq dired-recursive-copies (quote always))
(setq dired-recursive-deletes (quote top))
;; “always” means no asking.
;; “top” means ask once (top = top dir).
;; any other symbol means ask for each dir or subdir.

• File Management with Emacs
http://xahlee.org/emacs/file_management.html

-----------------------------------

if you are running emacs 23, deleting trash is already part of it.

Deleting files in emacs can now be set so that they move to the OS's trash.

; deleting files goes to OS's trash can
(setq delete-by-moving-to-trash t) ; “t” for true, “nil” for false

However, this feature has a few problems. When this is on, your system trash will be filled with tens or hundreds of emacs temp files, such as those “#autosave#” files, “backup~” files, “.emacs.desktop”, “emacs00164”, “server”, etc. Also, when deleting a directory from dired, your system trash will end up with each individual files, instead of just a folder. If the folder has few hundred files, the process will be super slow. This happens at least on Windows emacs.

• New Features in Emacs 23
http://xahlee.org/emacs/emacs23_features.html

Xah
∑ http://xahlee.org/

## 2009-08-24

### getting unicode to show in emacs 23 on Windows

i have this unicode file
http://xahlee.org/emacs/unicode.txt

when viewed in latest Safari, Google Chrome, Opera, Firefox, on Windows (Vista), all char shows. But many chars don't show in emacs 23 for Windows of the same machine. I tried many fonts... Courier New, Lucida Console, Lucida Sans Unicode... but none shows all as browsers do.

any one got idea how to fix this?

Lucida Sans Unicode shows most, but unfortunately, it's not monospaced font.

Thanks.

Xah
∑ http://xahlee.org/

---------------------

On Aug 25, 8:21 pm, Eli Zaretskii wrote:
> > Date: Tue, 25 Aug 2009 17:38:02 -0500
> > From: "B. T. Raven"
>
> > Could the glyphs that still show up as boxes (math, industrial,
> > computing, etc.) be made to appear if a fontset is used?
>
> I think so, but for me they appear without any customizations at all.
>
> > Why don't the ipa Symbols appear? They are part of Arial Unicode.
>
> I don't know enough about these issues. I suggest to submit a bug
> report with "M-x report-emacs-bug".

thanks Raven & Eli.

humm... it show for you Eli out of the box. Strange.

i don't have Arial Unicode MS, since it is part of Windows Office and OS X 10.5 both i don't have.

my current choice is Lucida Sans Unicode, which provide the most unicode chars among my choices, but is not monospaced font. Works out well, except dired, and unusable in M-x calendar. The unicode here also lacks a lot, e.g. half of the bottom page's chars won't show
http://xahlee.org/emacs/unicode.txt
but still is the font that shows the most on my machine.

Code2000 shows almost all the unicode, but the font is so bad... it's not readable.

Fixsys is also very good. Shows more unicode than Lucida Sans Unicode, but the only draw back is that its bitmapped. I just realized there's a Open Sourced TrueType one am going to try. (found from reading Wikipedia)

Courier New and Lucida Console are both very good. monospaced, but they don't show that much unicode except the most basic ones.

am guessing the problem really needs to be solved by some sort of font substitution. Browsers apparantly are all doing it and perfectly on my machine since they show all chars without user needing to set fonts.

i guess in emacs that is fontset? I'm not sure if it is just fontset, or emacs also calls the OS's font api to complete part of the display...

Eli, what version of emacs are you using? are you sure it's straight compile from source without customization?

Xah
∑ http://xahlee.org/

### Windows AutoHotKey: force single instance

is it possible to creat a key to launch/switch to Google Chrome, but do NOT launch a new instance if it is already running?

i know how to create a key to launch a app, but usually that will just launch a new instance.

one good example of what i want is Windows Mail, or the My Pictures special key on Microsoft keyboards. They just launch one instance, or switch to it, if it is already running.

Thanks.

Xah
∑ http://xahlee.org/

Answer:

• AutoHotKey Basics
http://xahlee.org/mswin/autohotkey.html

### emacs lisp function to copy dir and all sub dir?

is there a emacs lisp command to copy a whole dir? like unix's cp -R?

i started to write one:

(defun copy-dir (sourcedir destdir)
"Copy all files from SOURCEDIR to DESTDIR.

The input dir should not end in a slash.
Example usage:
(copy-dir
\"/Users/xah/web/p/um\"
\"/Users/xah/web/diklo/xx\")

Note: no consideration is taken about links, alias, or file perms."
(mapc
(lambda (x)
(let ()
(when (and (not (string-equal x ".")) (not (string-equal x "..")))
(copy-file
(concat sourcedir "/" x) destdir) ) ) )
(directory-files sourcedir) ) )

but it is hackish because of the checking with “.” and “..”,
but also realized this doesn't do sub dirs. In order to do subdir, it'll might end up with few hours more...

so, am wondering if there's a pre-made solutions?

Thanks.

Xah
∑ http://xahlee.org/

On Aug 26, 5:32 am, Michael Heerdegen wrote:
> Have a look at the doc of dired-recursive-copies'.

sorry all, but a bit clarification.

i needed a copy-dir function for elisp coding, not as user function in dired.

i haven't thought about looking into how dired-do-copy implement it, good thought. thanks.

looking into it, it seems a bit complex:

(defun dired-do-copy (&optional arg)
"Copy all marked (or next ARG) files, or copy the current file.
This normally preserves the last-modified date when copying.
When operating on just the current file, you specify the new name.
When operating on multiple or marked files, you specify a directory,
and new copies of these files are made in that directory
with the same names that the files currently have. The default
suggested for the target directory depends on the value of
dired-dwim-target', which see.

This command copies symbolic links by creating new ones,
like `cp -d'."
(interactive "P")
(let ((dired-recursive-copies dired-recursive-copies))
(dired-do-create-files 'copy (function dired-copy-file)
"Copy"
arg dired-keep-marker-copy
nil dired-copy-how-to-fn)))

is this the only way?

i think most modern scripting lang has a copy dir function... that'd be good in elisp.

Xah

------------------------------

for solution, see:

• Emacs Lisp Suggestion: A Function For Copying and Deleting Whole Dir
http://xahlee.org/emacs/modernization_elsip_copy_dir.html

## 2009-08-22

### emacs: make next word first letter cap then delete space

On Aug 22, 8:46 am, Harry Putnam wrote:
> I need to do a pile of editing that involves:
>
> Removing a space between words and upcasing the first letter of the
> next word like:
>
> Some example
> to
> SomeExample
>
> I went thru M-x apropos
>
> But didn't find a likely candidate ... or at least none appeared to be
> the right thing for what I want.
>
> So far I've been
>
> Ctrl To get to the space between words
> Ctrl-d Ctrl-d To remove the space and the leading lowercase char of
> the next word
>
> Shift to replace with uppercase
>
> Then back to Ctrl
>
> Where can I save some keyboard strokes?

you can easily do it with query-replace-regexp.

the regexp you should use is:

“ $$[[:lower:]]$$”

and the replacement is

“\,(upcase \1)”

some detail here:

• Text Pattern Matching in Emacs
http://xahlee.org/emacs/emacs_regex.html

• Find and Replace with Emacs
http://xahlee.org/emacs/emacs_find_replace.html

Xah
∑ http://xahlee.org/

### search word under cursor in emacs

On Aug 22, 4:07 am, lichtkind wrote:
> Hello,
>
> I have marked a string. Now I want to search for this string in the
> whole text. I know that I can search with C-R or C-S. and type in the
> searchstring. I'm looking for a way, that the marked string is
> automatic the searchstring. This should also work for the other
> search/ search and replace types.

if u are using emacs 22, then you can do this:

“Ctrl+s Ctrl+w”. This will search the current word, but you must move your cursor to the beginning of the word first.

In emacs 23, the above is deprecated. Basically, now you start it with M-s as prefix, then press some other key. It's rather complex and very not intuitive. I have 10 years of using emacs, but i did spent some 5 or 10 min reading the release notes... but i haven't figured it out.

You can, type M-s then C-h, to get a list of shortcuts that has M-s as start. You can read their command names there.

here's the output:

Global Bindings Starting With M-s:
key binding
--- -------

M-s h Prefix Command
M-s o occur
M-s w isearch-forward-word

M-s h f hi-lock-find-patterns
M-s h l highlight-lines-matching-regexp
M-s h p highlight-phrase
M-s h r highlight-regexp
M-s h u unhighlight-regexp
M-s h w hi-lock-write-interactive-patterns

ok, i just gave another try with M-s w. Spent another 2 min on this. Dunno what the fuck it is going.

someday i'll give a hour or two on this, maybe then i'll know the answer.

Xah
∑ http://xahlee.org/

## 2009-08-21

### where's emacs cheatsheet?

On Aug 21, 11:44 am, Ricardo Bánffy wrote:
> Hi folks.
>
> I am currently working (leisurely, for sure) on a cheatsheet for new
> Emacs users. It currently exists as a mind-map but will eventually
> become a freely available PDF more or less like the "navigational" one
> there is for git you can download athttp://zrusin.blogspot.com/2007/09/git-cheat-sheet.html
>
> The current version is linked onhttp://www.dieblinkenlights.com/blog_en/an-emacs-cheatsheet-as-a-mindmap.
>
> Thanks. Any comments, from newbies and veterans alike, will be
> appreciated.

be sure to consult existing work.

emacs comes with a bunch of cheatsheets in tex and pdf. Look in: e.g.

c:/Program Files (x86)/Emacs/emacs/etc/refcards

Xah
∑ http://xahlee.org/

### emacs: code to cycle buffer & skip emacs internal ones

On Aug 21, 5:31 pm, Chris Seberino wrote:
> When I cycle through buffers, I'd like to skip *scratch*, *Messages*
> and *Whitespace Errors* buffers.
>
> I wrote following code to skip one more buffer if I'm sitting in
> either of those 3.
>
> However, it never matches those buffers. Why not?
>
> (BTW, the (end-kbd-macro) is just a dummy function since "if" needs an
> "else" command.
> Is there a better dummy command I can add there?)
>
> ; Sets F10 to execute a function that moves to another buffer.
> (global-set-key [f10] (lambda () (interactive)
> (next-buffer)
> (if (equal (current-buffer)
> "*scratch*")
> (next-buffer)
> (end-kbd-macro))
> (if (equal (current-buffer)
> "*Messages*")
> (next-buffer)
> (end-kbd-macro))
> (if (equal (current-buffer)
> "*Whitespace Errors*")
> (next-buffer)
> (end-kbd-macro))))

Wee, the code to skip emacs buffers is in ergoemacs here:
http://code.google.com/p/ergoemacs/

by default it's Ctrl + Page up/down is the shortcut, similar to Firefox et al for switching tabs.
With shift key down, it cycle among emacs's buffers.

here's the relevant code:

(defun next-user-buffer ()
"Switch to the next user buffer.
User buffers are those whose name does not start with *."
(interactive)
(next-buffer)
(let ((i 0))
(while (and (string-match "^*" (buffer-name)) (< i 50))
(setq i (1+ i)) (next-buffer) )))

Xah
∑ http://xahlee.org/

### try upgrade ergoemacs keybinding

On Aug 21, 9:56 am, Benjamin Andresen wrote:
> Xah Lee writes:
> > On Aug 20, 10:50 pm, Torben Knudsen wrote:
> [snip]
> >> I use something similar. My idea is to stay close to original emacs
> >> bindings but to avoid to many key strokes.
>
> >> ;;; Window splitting
> >> (global-set-key (kbd "M-3") 'split-window-horizontally) ; was digit-argument
> >> (global-set-key (kbd "M-2") 'split-window-vertically) ; was digit-argument
> >> (global-set-key (kbd "M-1") 'delete-other-windows) ; was digit-argument
> >> (global-set-key (kbd "M-0") 'delete-window) ; was digit-argument
> >> (global-set-key (kbd "M-o") 'other-window) ; was prefix
> >> ;; Remove locale key binding of M-o in dired
> >> (add-hook 'dired-mode-hook 'my-dired-mode-hook)
> >> (defun my-dired-mode-hook ()
> >> (define-key dired-mode-map (kbd "M-o") nil)) ; was dired-omit-mode
>
> > umm.. that code looks like from
> >http://code.google.com/p/ergoemacs/
>
> It doesn't. None of these lines appear as they are in ergoemacs.

look at old versions. Go to code.google.com, download tab, then in the search, choose All Downloads. That will show older versions.

i noticed in many if not most tech geeker's projects hosted on google code, they don't bother to mark older version as deprecated. So, their download pages shows ALL the past versions. It kinda makes the page full and glorious, and shows the download numbers. But i think its silly and unhelpful...

Xah

### tab key abused in emacs

On Aug 20, 9:08 am, "Farhan Ahmed" wrote:
>
> FWIW, I've mapped shift+TAB to 'next buffer and C+shift+TAB to 'previous
> buffer and now I only use one window to edit code. Takes a little getting
> used to, but it works.

using Tab is probably worst, because every mode vie for that key.

in just about all modes, tab does indentation.

ysnippet also uses tabs.

org mode uses tabs.

in minibuffer and elsewhere, it's also used for completion.

not recommended to pile on such a key. Also, i noticed, tab key is not actually a good key. Need to take care of your pinkies.

Xah
∑ http://xahlee.org/

## 2009-08-20

### easy way to switch panes in emacs

On Aug 20, 1:58 am, Tamas K Papp wrote:
> Hi,
>
> I have seen screenshots of Emacs running with many buffers. For
> example, having Emacs on the whole screen and splitting the buffers
> like this:
>
> A|B
> -+-
> C|D
>
> I know how to do the splitting, but I am curious about what people use
> to move around. Using C-x o (other-window) is a pain with many
> windows, same applies to selecting buffers by name (at least for me),
> and I want to avoid using the mouse for this. I am thinking of
> something like "move to buffer B, regardless of what is there".
>
> I am interested in how other people handle these setups. .emacs
> snippets are welcome, too. Also, feel free to tell me if I am
> trying to do something silly that does not mesh well with Emacs.

I reassign it so the key is right on the home row and using thumb instead of pinky.

after a year or two, this eventually became a system of keybinding.
http://code.google.com/p/ergoemacs/

then, later i added a shifted version to go into the other direction.

typically, this works well for 2 or 3 split panes. But for 4 or more, mouse is probably best.
I almost don't use more than 2 split planes. If needed, i open another window (emacs frame), then there's another easy shortcut to cycle among windows.

you might as well define another easy key to easily split and unsplit the panes.

Here's snippet of code, assuming you use dvorak keyboard:

(global-set-key (kbd "M-o") 'move-cursor-next-pane)
(global-set-key (kbd "M-O") 'move-cursor-previous-pane)

(global-set-key (kbd "M-2") 'split-window-vertically)
(global-set-key (kbd "M-@") 'split-window-horizontally)

(global-set-key (kbd "M-1") 'delete-other-windows)
(global-set-key (kbd "M-!") 'delete-window)

Xah
∑ http://xahlee.org/

## 2009-08-19

### which keys can user define in emacs?

On Aug 18, 5:58 pm, "Mark" wrote:
> Hello
>
> by default key-bindings for tags operations (find tag, find next tag etc.)
> are quite twisted and hard to remember, comparing to vim' default keys. Is
> there any other way to define more 'easy-to-use' bindings? I know I can
> re-define any key, but as I know not every key sequence is permitted to be
> used by end-user and those that are, are not very "handy" involving F1-F10
> keys or the like. Especially I'd love to have opportunity when find a tag,
> to open a file containing the tag in a new window (similar to Ctrl-W Ctrl-]
> in vim).
>
> So how do people deal with default tags options while editing for example
> C/C++ code? Can you please share your key-bindings for these cases, if I
> find them comfortable to use I'd be more happy with Emacs :)

well i use ergoemacs.
http://code.google.com/p/ergoemacs/

perhaps give it a try?

of course you can define any key. And yes most “Ctrl+‹key›” and “Alt+‹key›” spaces are already used. This is partly why emacs has a convention where “Ctrl+c ‹letter›” space is for users. If you do not wish to step over emacs keys or official convention, then “Ctrl+c ‹letter›” and F5 to F9 is pretty much the only one you can use.

However, if you look carefully, you'll see there are probably quite a few spots in “Ctrl+‹key›” and “Alt+‹key›” spaces that are bound to commands you never use. Might want to steal it then.

This might be helpful

• Emacs's Keybinding Layout
http://xahlee.org/emacs/emacs_kb_shortcuts.html

Xah
∑ http://xahlee.org/

### how to prevent emacs losing unsafed un-file buffers when quit

On Aug 19, 5:22 pm, YOUNG wrote:
> Hi,
>
> If a buffer does not connect to a file but it is modified, if you type
> c-x c, emacs just quits and losts the data.
>
> Is there a way to protect of it?

I don't think there's a default way. This is one of the problem that pains me.

But if you use ergoemacs
http://code.google.com/p/ergoemacs/

it's fixed there.

--------------------------------

On Aug 19, 7:09 pm, Xah Lee wrote:
> On Aug 19, 5:22 pm, YOUNG wrote:
>
> > Hi,
>
> > If a buffer does not connect to a file but it is modified, if you type
> > c-x c, emacs just quits and losts the data.
>
> > Is there a way to protect of it?
>
> I don't think there's a default way. This is one of the problem that
> pains me.
>
> But if you use ergoemacshttp://code.google.com/p/ergoemacs/
>
> it's fixed there.

O, just tried to reproduce your situation but there's a bit warning.

When you use ergoemacs, you can create buffers by Ctrl+n, which calls new-empty-buffer. Then, in this buffer, if modified and not saved, when you try to close it or quit emacs, emacs will prompt you to save it.

However, it does not fix when if you just use switch-to-buffer (C-x b) command to create a new buffer.

Here's the relevant source code. Note the line
(setq buffer-offer-save t).
Feel free to use it.

(defun new-empty-buffer ()
"Opens a new empty buffer."
(interactive)
(let ((buf (generate-new-buffer "untitled")))
(switch-to-buffer buf)
(funcall (and initial-major-mode))
(setq buffer-offer-save t)))
;; note: emacs won't offer to save a buffer that's
;; not associated with a file,
;; even if buffer-modified-p is true.
;; One work around is to define your own my-kill-buffer function
;; that wraps around kill-buffer, and check on the buffer modification
;; status to offer save
;; This custome kill buffer is close-current-buffer.

Xah
∑ http://xahlee.org/

## 2009-08-17

### emacs cult

> Please do not slag off a project if you want people to help;
> it tends to put the goat up.

a healthy community needs both positive comment as well as negative to grow.

emacs's user base has been rotting off from i estimate more than 50% of programers to less that 1% today.

the particular observation about info doc in this thread is a specific example.

You can help FSF and emacs to improve, by, for example, trying to help it to evolve with the rapidly changing computing industry, In this case, document formats, provided if you see some of my points as valid. Or, at least consider this eroding awareness of the gnu info format among average programers worth discussing. No disrespect to you, but dismissing it as “troll” or similiar sentiment is not helpful.

emacs community is too much cult and pride. FSF and its product the GNU was highly successful in the 1980 and 1990s, with its gcc, emacs, and slew of gnu version of unix tools. A significant part of the reason is because these products at the time is truely better products in comparison to existing ones, that there are almost no substitute. Today, for many variety and complexity of reasons, almost none of this is true, except possiblly a few such as gcc and GPG. The unix shells ways and sed, awk, etc tools has largely been replaced by perl, python, ruby etc, partly due to the changing nature of computing. For GCC itself, and make, yacc, bison etc there are tens of competiting products either commercial or open source. Then there's Java, with its entire suite of tools and libs, and there are tens of truely quality languages out there today other then the ones that GCC can handle.

emacs 23, although is fantastic to us emacs fans, but if you look carefully at its feature list, most of it is widely in commericial software about 10 years ago.

Xah
∑ http://xahlee.org/

On Aug 17, 4:32 am, "Colin S. Miller" wrote:
> Xah Lee wrote:
> > btw, is there still info format for python doc?
>
> > i feel kinda sad that emacs info format has pretty much been
> > deprecated over the past decade. About a decade ago, you still will
> > see now and then people asking for emacs info format of docs (was the
> > days of perl). Today, one don't hear of it.
>
> > Part of this is due to emacs cult problem. See:
>
> Xah,
>
> Please do not slag off a project if you want people to help;
> it tends to put the goat up.
>
> It is not "Emacs Info" format, it is FSF Info format.
> There is a stand-alone program to read the Info documentation.
> The program is called "info".
>
> Ubuntu maintains a package search site, it is onhttp://packages.ubuntu.com/
>
> However, there seems to be no files named
> python.*info (regexp)
>
> There is a
> python-docutils package
> which does contain information in several
> other formats.
>
> This package can be found either via the above site
> or using "apt-cache search python-doc".
>
> As "info" is a FSF format, all FSF produced programs
> will provide documentation in this format. However Python
> is not under the auspices of the FSF, so does not need to use
> this format.
>
> BTW,
> HTML versions of INFO documentation can be generated by
> info2html or info_to_html on them, or texi2html on the source.
>
> Have a nice day,
> Colin S. Miller