## 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}

• 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/