Article View: gnu.emacs.help
Article #189270Re: isearch question
From: Hamish Macdonald
Date: Fri, 15 Mar 1991 14:21
Date: Fri, 15 Mar 1991 14:21
85 lines
4352 bytes
4352 bytes
|> why doesn't backspace shorten the search string and
|> backup so that it finds the shortened string?
> It does! Well, search-delete-char does; this is normally DEL.
This is precisely the reason people who want to use the backspace key
for delete-type things should use the keyboard translate table to swap
backspace and delete rather than changing keybindings. There's all
these little gotchas that getcha if you just change the keybindings.
Here follows something Deven Corzine once posted to swap the keys:
---------------------------------------------------------------------------
On 3 Feb 90 18:39:18 GMT, mikef@sarah.lerc.nasa.gov (Mike J. Fuller) said:
mikef> I'm posting this because I have seen more than a few requests
mikef> for this recently. Just put this in your .emacs file:
mikef> (progn
mikef> (setq keyboard-translate-table (make-string 128 0))
mikef> (let ((i 0))
mikef> (while (< i 128)
mikef> (aset keyboard-translate-table i i)
mikef> (setq i (1+ i)))))
mikef> (aset keyboard-translate-table ?\^? ?\^h)
mikef> (aset keyboard-translate-table ?\^h ?\^?)
This seems to be the solution everyone has posted. I wrote a somewhat
more extensive function, which is intended to work even if
keyboard-translate-table already exists, and it swaps the real
bindings of backspace and delete, not hardcoding the real values.
Also, the function can be called interactively to swap the keys at any
time, and can be called noninteractively, forcing swapped or unswapped.
(When forcing one or the other mapping, it does use hardcoded bs or
del chars instead of what's in their positions in the current
keyboard-translate-table.
Here is the function:
(defun swap-bs-del (&optional arg)
"Accepts single optional argument. If no argument, or nil, swaps values
for backspace and delete keys in keybpoard-translate-table, initializing
table if necessary. If arg is t or an integer greater than 0, forces a
mapping of bs->del and del->bs. Any other argument forces untranslated
mapping of bs->bs and del->del."
(interactive)
;; initialize keyboard-translate-table
(if (not keyboard-translate-table)
(setq keyboard-translate-table ""))
(let ((char (length keyboard-translate-table)))
(while (< char 128)
(setq keyboard-translate-table
(concat keyboard-translate-table (char-to-string char))
char (1+ char))))
;; check arg
(if (not arg)
;; no arg or nil, swap backspace and delete
(let ((bs (aref keyboard-translate-table 8))
(del (aref keyboard-translate-table 127)))
(aset keyboard-translate-table 8 del)
(aset keyboard-translate-table 127 bs))
;; argument given
(if (or (eq arg t)
(and (integerp arg)
(> arg 0)))
;; t or integer greater than zero, force bs->del, del->bs
(progn
(aset keyboard-translate-table 127 8)
(aset keyboard-translate-table 8 127))
;; other argument, force untranslated bs->bs, del->del
(aset keyboard-translate-table 8 8)
(aset keyboard-translate-table 127 127))))
Enjoy!
Deven
--
Deven T. Corzine Internet: deven@rpi.edu, shadow@pawl.rpi.edu
Snail: 2151 12th St. Apt. 4, Troy, NY 12180 Phone: (518) 274-0327
Bitnet: deven@rpitsmts, userfxb6@rpitsmts UUCP: uunet!rpi!deven
Simple things should be simple and complex things should be possible.
--
--------------------------------------------------------------------
himacdon@maytag.uwaterloo.ca watmath!maytag!himacdon
Technical Details
Message-ID:
<1991Mar15.142114.5109@maytag.waterloo.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!watmath!maytag!maytag!himacdonReferences:
<9103142126.AA29444@chaos.cs.brandeis.edu> <1991Mar15.033524.21830@mprgate.mpr.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,61f3acf7b9f3e94f X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-03-15 06:52:31 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!watmath!maytag!maytag!himacdon From: himacdon@maytag.uwaterloo.ca (Hamish Macdonald) Newsgroups: gnu.emacs.help Subject: Re: isearch question Message-ID: <1991Mar15.142114.5109@maytag.waterloo.edu> Date: 15 Mar 91 14:21:14 GMT References: <9103142126.AA29444@chaos.cs.brandeis.edu> <1991Mar15.033524.21830@mprgate.mpr.ca> Sender: daemon@maytag.waterloo.edu (Admin) Organization: University of Waterloo, Waterloo, Ontario Lines: 85 In-Reply-To: manderso@spain.mpr.ca's message of 15 Mar 91 03:35:24 GMT