* if I set home key to this macro then shift+home does not select text in cua-mode
@ 2008-11-25 0:21 Tolkin, Steve
0 siblings, 0 replies; 6+ messages in thread
From: Tolkin, Steve @ 2008-11-25 0:21 UTC (permalink / raw)
To: help-gnu-emacs
Summary: If I bind the home key to the macro below and press shift+home
it does not select the text.
Details:
I am running GNU Emacs 22.3.1 on of 2008-09-96 on SOFT-MJASON. On
windows XP SP2.
This used to work in emacs 22. I suspect the problem has to do with
changes to cua-mode (which I have on) and/or transient mark-mode (which
I explicitly set on in v. 22,but now seems to be part of cua-mode.)
Here is the macro definition:
;; Posted to comp.emacs by:
;; Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
(defun my-home ()
"Toggle the point between the beginning of the current line, and the
first non-whitespace character on the line."
(interactive)
(let ((pos (save-excursion (back-to-indentation) (point))))
(if (equal pos (point))
(beginning-of-line)
(back-to-indentation))))
(global-set-key [home] 'my-home)
My current workaround is simply to comment out the global-set-key line.
Is there a fix to the macro to get the old behavior? Even better would
be something already in cua-mode or simple.el etc that i could use.
Note: I am now also sending this to help-gnus-emacs because it was
suggested on the h-e-w list that this was not specific to Windows.
Thanks,
Steve
--
Steven Tolkin
There is nothing so practical as a good theory. Comments are by me,
not Fidelity Investments, its subsidiaries or affiliates.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: if I set home key to this macro then shift+home does not select text in cua-mode
[not found] <mailman.1213.1227617025.26697.help-gnu-emacs@gnu.org>
@ 2008-11-25 13:57 ` Xah Lee
2008-11-25 16:14 ` Tolkin, Steve
2008-11-25 16:27 ` Lennart Borgman
0 siblings, 2 replies; 6+ messages in thread
From: Xah Lee @ 2008-11-25 13:57 UTC (permalink / raw)
To: help-gnu-emacs
On Nov 24, 4:21 pm, "Tolkin, Steve" <Steve.Tol...@FMR.COM> wrote:
> Summary: If I bind the home key to the macro below and press shift+home
> it does not select the text.
>
> Details:
> I am running GNU Emacs 22.3.1 on of 2008-09-96 on SOFT-MJASON. On
> windows XP SP2.
> This used to work in emacs 22. I suspect the problem has to do with
> changes to cua-mode (which I have on) and/or transient mark-mode (which
> I explicitly set on in v. 22,but now seems to be part of cua-mode.)
>
> Here is the macro definition:
>
> ;; Posted to comp.emacs by:
> ;; Kai Grossjohann <Kai.Grossjoh...@CS.Uni-Dortmund.DE>
> (defun my-home ()
> "Toggle the point between the beginning of the current line, and the
> first non-whitespace character on the line."
> (interactive)
> (let ((pos (save-excursion (back-to-indentation) (point))))
> (if (equal pos (point))
> (beginning-of-line)
> (back-to-indentation))))
>
> (global-set-key [home] 'my-home)
>
> My current workaround is simply to comment out the global-set-key line.
> Is there a fix to the macro to get the old behavior? Even better would
> be something already in cua-mode or simple.el etc that i could use.
>
> Note: I am now also sending this to help-gnus-emacs because it was
> suggested on the h-e-w list that this was not specific to Windows.
Few notes and answers.
• what you called a macro is not a macro. It is just a lisp function,
or call it user written emacs command. A macro in emacs has 2
meanings: keyboard macro, and elisp macro. Keyboard macro is software
application feature that allows you to record your keystrokes and play
them back. It's purpose is to let you do a lot automations. As a
example, a OS wide macro system is QuicKeys. A lisp macro is a fetarue
of the computer language that allows you do do source code
transformation. In some sense, it is a crude form of term rewriting
languages. (e.g. Mathematica)
you can read about these here:
http://en.wikipedia.org/wiki/Macro_(computer_science)
http://en.wikipedia.org/wiki/Rewriting
http://en.wikipedia.org/wiki/Mathematica
As to your question, you can make it work by this:
(add-hook 'cua-mode-hook
(lambda ()
(put 'my-home 'CUA 'move)
)
)
probably best to rename your function to something more descriptive,
such as
line-beginning-dwim . (the “dwim” means “do what i mean”, as in
comment-dwim.)
also, you might be interested in these commands:
just-one-space
delete-horizontal-space
both have default keyboard shortcuts.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: if I set home key to this macro then shift+home does not select text in cua-mode
2008-11-25 13:57 ` if I set home key to this macro then shift+home does not select text in cua-mode Xah Lee
@ 2008-11-25 16:14 ` Tolkin, Steve
2008-11-25 16:56 ` Tolkin, Steve
[not found] ` <mailman.1236.1227635531.26697.help-gnu-emacs@gnu.org>
2008-11-25 16:27 ` Lennart Borgman
1 sibling, 2 replies; 6+ messages in thread
From: Tolkin, Steve @ 2008-11-25 16:14 UTC (permalink / raw)
To: Xah Lee, help-gnu-emacs
Dear Xah,
Thanks. Why did I have to compile it for it to work?
First I added this to my _emacs init file and then I tried it by doing a load-file of ~/_emacs
But it did not work.
Then I ran byte-compile-file ~/_emacs and then a load-file of ~/_emacs.elc
I pasted this just after the global-set-key line in my _emacs file and
;;; next suggested by Xah Lee email 11/25/08
(add-hook 'cua-mode-hook
(lambda ()
(put 'my-home 'CUA 'move)
)
)
Steve
-----Original Message-----
From: help-gnu-emacs-bounces+steve.tolkin=fmr.com@gnu.org [mailto:help-gnu-emacs-bounces+steve.tolkin=fmr.com@gnu.org] On Behalf Of Xah Lee
Sent: Tuesday, November 25, 2008 8:57 AM
To: help-gnu-emacs@gnu.org
Subject: Re: if I set home key to this macro then shift+home does not selecttext in cua-mode
On Nov 24, 4:21 pm, "Tolkin, Steve" <Steve.Tol...@FMR.COM> wrote:
> Summary: If I bind the home key to the macro below and press shift+home
> it does not select the text.
>
> Details:
> I am running GNU Emacs 22.3.1 on of 2008-09-96 on SOFT-MJASON. On
> windows XP SP2.
> This used to work in emacs 22. I suspect the problem has to do with
> changes to cua-mode (which I have on) and/or transient mark-mode (which
> I explicitly set on in v. 22,but now seems to be part of cua-mode.)
>
> Here is the macro definition:
>
> ;; Posted to comp.emacs by:
> ;; Kai Grossjohann <Kai.Grossjoh...@CS.Uni-Dortmund.DE>
> (defun my-home ()
> "Toggle the point between the beginning of the current line, and the
> first non-whitespace character on the line."
> (interactive)
> (let ((pos (save-excursion (back-to-indentation) (point))))
> (if (equal pos (point))
> (beginning-of-line)
> (back-to-indentation))))
>
> (global-set-key [home] 'my-home)
>
[some snipped]
As to your question, you can make it work by this:
(add-hook 'cua-mode-hook
(lambda ()
(put 'my-home 'CUA 'move)
)
)
[more snipped]
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: if I set home key to this macro then shift+home does not select text in cua-mode
2008-11-25 13:57 ` if I set home key to this macro then shift+home does not select text in cua-mode Xah Lee
2008-11-25 16:14 ` Tolkin, Steve
@ 2008-11-25 16:27 ` Lennart Borgman
1 sibling, 0 replies; 6+ messages in thread
From: Lennart Borgman @ 2008-11-25 16:27 UTC (permalink / raw)
To: Xah Lee; +Cc: help-gnu-emacs
On Tue, Nov 25, 2008 at 2:57 PM, Xah Lee <xahlee@gmail.com> wrote:
> As to your question, you can make it work by this:
>
> (add-hook 'cua-mode-hook
> (lambda ()
> (put 'my-home 'CUA 'move)
> )
> )
Isn't it enough with just
(put 'my-home 'CUA 'move)
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: if I set home key to this macro then shift+home does not select text in cua-mode
2008-11-25 16:14 ` Tolkin, Steve
@ 2008-11-25 16:56 ` Tolkin, Steve
[not found] ` <mailman.1236.1227635531.26697.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 6+ messages in thread
From: Tolkin, Steve @ 2008-11-25 16:56 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: Xah Lee
Sorry, my earlier statement that compiling the _emacs file changed the behavior was wrong.
Pressing Shift+home sometimes does the selection and sometimes it does not.
I do not know what causes this.
(The home key is assocated with the my-home lisp code below, and I added Xah's code to my _emacs.)
After I exited emacs and restarted it it no longer does the selection at all.
Steve
-----Original Message-----
From: Tolkin, Steve
Sent: Tuesday, November 25, 2008 11:15 AM
To: 'Xah Lee'; help-gnu-emacs@gnu.org
Subject: RE: if I set home key to this macro then shift+home does not select text in cua-mode
Dear Xah,
Thanks. Why did I have to compile it for it to work?
First I added this to my _emacs init file and then I tried it by doing a load-file of ~/_emacs
But it did not work.
Then I ran byte-compile-file ~/_emacs and then a load-file of ~/_emacs.elc
I pasted this just after the global-set-key line in my _emacs file and
;;; next suggested by Xah Lee email 11/25/08
(add-hook 'cua-mode-hook
(lambda ()
(put 'my-home 'CUA 'move)
)
)
Steve
-----Original Message-----
From: help-gnu-emacs-bounces+steve.tolkin=fmr.com@gnu.org [mailto:help-gnu-emacs-bounces+steve.tolkin=fmr.com@gnu.org] On Behalf Of Xah Lee
Sent: Tuesday, November 25, 2008 8:57 AM
To: help-gnu-emacs@gnu.org
Subject: Re: if I set home key to this macro then shift+home does not selecttext in cua-mode
On Nov 24, 4:21 pm, "Tolkin, Steve" <Steve.Tol...@FMR.COM> wrote:
> Summary: If I bind the home key to the macro below and press shift+home
> it does not select the text.
>
> Details:
> I am running GNU Emacs 22.3.1 on of 2008-09-96 on SOFT-MJASON. On
> windows XP SP2.
> This used to work in emacs 22. I suspect the problem has to do with
> changes to cua-mode (which I have on) and/or transient mark-mode (which
> I explicitly set on in v. 22,but now seems to be part of cua-mode.)
>
> Here is the macro definition:
>
> ;; Posted to comp.emacs by:
> ;; Kai Grossjohann <Kai.Grossjoh...@CS.Uni-Dortmund.DE>
> (defun my-home ()
> "Toggle the point between the beginning of the current line, and the
> first non-whitespace character on the line."
> (interactive)
> (let ((pos (save-excursion (back-to-indentation) (point))))
> (if (equal pos (point))
> (beginning-of-line)
> (back-to-indentation))))
>
> (global-set-key [home] 'my-home)
>
[some snipped]
As to your question, you can make it work by this:
(add-hook 'cua-mode-hook
(lambda ()
(put 'my-home 'CUA 'move)
)
)
[more snipped]
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: if I set home key to this macro then shift+home does not select text in cua-mode
[not found] ` <mailman.1236.1227635531.26697.help-gnu-emacs@gnu.org>
@ 2008-11-25 20:20 ` Xah Lee
0 siblings, 0 replies; 6+ messages in thread
From: Xah Lee @ 2008-11-25 20:20 UTC (permalink / raw)
To: help-gnu-emacs
On Nov 25, 8:14 am, "Tolkin, Steve" <Steve.Tol...@FMR.COM> wrote:
> Thanks. Why did I have to compile it for it to work?
> First I added this to my _emacs init file and then I tried it by doing a load-file of ~/_emacs
> But it did not work.
> Then I ran byte-compile-file ~/_emacs and then a load-file of ~/_emacs.elc
Basically, when you modify a mode's hook, and that mode has already
been loaded, it won't re-load your new hook's value.
there are ways... but the simplest method is to restart emacs when you
modified a hook.
You don't need to byte compile it, and byte compiling shouldn't have
anything to do with this.
On Nov 25, 8:56 am, "Tolkin, Steve" <Steve.Tol...@FMR.COM> wrote:
> Sorry, my earlier statement that compiling the _emacs file changed the behavior was wrong.
> Pressing Shift+home sometimes does the selection and sometimes it does not.
> I do not know what causes this.
Looking at your function, you probably also want to add back-to-
indentation the CUA property of “'move”. So, try this new hook:
(add-hook 'cua-mode-hook
(lambda ()
(put 'my-home 'CUA 'move)
(put 'back-to-indentation 'CUA 'move)
)
)
basically, what the above hooks do is that when cua mode is loaded,
add the property of “'move” to the symbol “'my-home”. Same for the
other. In lisp, symbols can have properties... this “symbol” concept
and its “property” is not something typical programing langs has. (the
other symbolic lang i know, Mathematica, has the same symbol and
property concepts. But i don't think any other functional langs such
as Haskell, OCml, erlang ... has it.)
Overall, what you are doing is not something simple. Because the
implementation of CUA mode is rather a complex. The reason it is
complex because it has to remain compatible with emacs's ways. Namely,
first: C-x key for copy has to remain functional for emacs's
traditional use of C-x key as a prefix. Secondly, the model of holding
Shift down while pressing other cursor movement key to cause text
selection is not something emacs do. So, making these work takes some
exploitation of elisp system. And now, you wanted to added your own
rather non-standard cursor movement function, and want the Shift+move
model to work on that too...
if the above works for you, that's great... but i think exploring
other ways of editing of doing what you want might be worthwhile.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-11-25 20:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1213.1227617025.26697.help-gnu-emacs@gnu.org>
2008-11-25 13:57 ` if I set home key to this macro then shift+home does not select text in cua-mode Xah Lee
2008-11-25 16:14 ` Tolkin, Steve
2008-11-25 16:56 ` Tolkin, Steve
[not found] ` <mailman.1236.1227635531.26697.help-gnu-emacs@gnu.org>
2008-11-25 20:20 ` Xah Lee
2008-11-25 16:27 ` Lennart Borgman
2008-11-25 0:21 Tolkin, Steve
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.