[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: weirdness with no-break space, fset and defun

From: Yuri Khan
Subject: Re: weirdness with no-break space, fset and defun
Date: Sun, 2 Aug 2015 17:13:49 +0600

On Sun, Aug 2, 2015 at 4:10 PM, Toomas Rosin <address@hidden> wrote:

> I have a text file in which I want to occasionally overwrite regular
> spaces (<U0020>, #x20) with UTF-8 no-break spaces (<U00A0>).  Trying to
> define a shortcut key for this (C-c SPC, which is a lot easier to type
> frequently than C-x 8 SPC), I ran into a bit of trouble.  I got it right
> finally, but am still puzzled about why my first attempts failed.

Why are you trying to solve that in Emacs and not on your desktop
environment level?

On X, enable the XKB option nbsp:level4. This way you will be able to
type the non-breaking space by pressing the space bar while holding
down Shift and Level3. Which key you use for Level3 is customizable
but the default Estonian layout puts it on the right Alt.

The command is:

$ setxkbmap ee -option nbsp:level4

(Depending on your specific desktop environment, you may have a GUI
settings dialog where you can specify this option.)

(If you are careful and use the non-breaking space a lot, you may want
to enable nbsp:level3 instead. This way you don’t need to hold Shift.
But then you might accidentally enter a non-breaking space when you
mean an ordinary space.)

On Windows, you can use the MSKLC tool to add the non-breaking space
to your layout.

On Mac, use Option+Space.

On the Linux console or mobile devices, I don’t know of an easy solution.

Characters entered via the desktop environment input methods are
treated in Emacs as ordinary self-inserting characters. They work in
the GUI Emacs and text-based Emacs running in a terminal emulator,
including over SSH. As a bonus, they work in all your other
applications that use standard character input facilities. (Remote
desktop solutions may present a problem.)

>     M-: (fset SPC 'insert-no-break-space SPC " C-x 8 SPC ") RET

This is a keyboard macro whose body is a single character, namely,
non-breaking space. For some reason, the macro engine interprets it as
M-SPC (which you can find out by asking for documentation on the
macro: C-h f insert-no-break-space). When you invoke the macro, M-SPC
runs the command just-one-space.

> When I do, instead,
>     M-: (defun SPC insert-no-break-space SPC () SPC (interactive) SPC (insert 
> SPC " C-x 8 SPC ")) RET

This is an Emacs Lisp command definition which specifically inserts a
non-breaking space without checking whether the overwrite-mode is

> The method I arrived at at last is the following:
>     M-: (fset SPC 'insert-no-break-space SPC " C-q C-x 8 SPC ") RET
> (i.e. with C-q before C-x).  This does exactly what I need.

This is a keyboard macro whose body consists of three characters:
control character ^X, the digit 8, and the space. When you invoke it,
this key sequence invokes a command that inserts a non-breaking space
according to the current state of overwrite-mode.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]