all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* weirdness with no-break space, fset and defun
@ 2015-08-02 10:10 Toomas Rosin
  2015-08-02 11:13 ` Yuri Khan
  0 siblings, 1 reply; 2+ messages in thread
From: Toomas Rosin @ 2015-08-02 10:10 UTC (permalink / raw
  To: help-gnu-emacs

Good <insert your local time of day here>!

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.

When I do

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

, the result depends on where the point is located.  After a regular
space (#0x20), this command has absolutely no effect; elsewhere it
inserts a *regular* (instead of no-break) space, *without overwriting
the next character* in overwrite mode!

When I do, instead,

    M-: (defun SPC insert-no-break-space SPC () SPC (interactive) SPC (insert SPC " C-x 8 SPC ")) RET

    M-x insert-no-break-space RET

, the command inserts a no-break space all right, but still does not
overwrite the next character in overwrite mode.

(I did these experiments first in a regular Emacs session, but the same
happened with "LANG=C emacs --no-init".  I have Emacs 24.4.1, a fairly
regular build: "--prefix=/usr --with-gif=no --localstatedir=/var", with
X libraries.)

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.

I am confused.  What's going on?  Am I missing something I should know?

With best wishes,
T.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: weirdness with no-break space, fset and defun
  2015-08-02 10:10 weirdness with no-break space, fset and defun Toomas Rosin
@ 2015-08-02 11:13 ` Yuri Khan
  0 siblings, 0 replies; 2+ messages in thread
From: Yuri Khan @ 2015-08-02 11:13 UTC (permalink / raw
  To: Toomas Rosin; +Cc: help-gnu-emacs@gnu.org

On Sun, Aug 2, 2015 at 4:10 PM, Toomas Rosin <toomas@rosin.ee> 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
enabled.


> 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.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-02 11:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-02 10:10 weirdness with no-break space, fset and defun Toomas Rosin
2015-08-02 11:13 ` Yuri Khan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.