* Problems with the capitalization in Word Abbreviation Mode
@ 2008-10-06 8:12 Hans-Christian Mick
2008-10-06 13:12 ` Andreas Politz
2008-10-07 4:06 ` Xah
0 siblings, 2 replies; 7+ messages in thread
From: Hans-Christian Mick @ 2008-10-06 8:12 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I'm writing a paper in German and trying to automaticalliy fix some of
my usual typos by using the Word Abbreviation mode (and I have to
admit that I'm rather new to Emacs...).
I'm having a problem with the capitalization in those abbreviations.
A typo that happens to me rather often is that for example I'm typing
"DAs" instead of "Das" at the beginning of a sentence.
I have tried to define a global abbreviation for that, but now I'm
getting every "das" in the middle of a sentence turned into "Das",
which is not what I wanted of course.
Looking into my abbrev.defs-file, I did not find the abbreviation
"DAs" that I originally had defined, but only a lowercase "das" and I
couldn't change it even by modifying the file directly (I wrote "DAs"
into the file, but then it didn't work anymore at all).
Seems as if I'm always getting a lowercase abbreviation, no matter how
I'm defining my abbreviations.
Could anyone please give me any hint on how to change this behaviour?
Thanks a lot in advance!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problems with the capitalization in Word Abbreviation Mode
2008-10-06 8:12 Problems with the capitalization in Word Abbreviation Mode Hans-Christian Mick
@ 2008-10-06 13:12 ` Andreas Politz
2008-10-06 14:31 ` Hans-Christian Mick
2008-10-07 4:06 ` Xah
1 sibling, 1 reply; 7+ messages in thread
From: Andreas Politz @ 2008-10-06 13:12 UTC (permalink / raw)
To: help-gnu-emacs
Hans-Christian Mick wrote:
> Hello,
>
> I'm writing a paper in German and trying to automaticalliy fix some of
> my usual typos by using the Word Abbreviation mode (and I have to
> admit that I'm rather new to Emacs...).
>
> I'm having a problem with the capitalization in those abbreviations.
>
> A typo that happens to me rather often is that for example I'm typing
> "DAs" instead of "Das" at the beginning of a sentence.
> I have tried to define a global abbreviation for that, but now I'm
> getting every "das" in the middle of a sentence turned into "Das",
> which is not what I wanted of course.
>
> Looking into my abbrev.defs-file, I did not find the abbreviation
> "DAs" that I originally had defined, but only a lowercase "das" and I
> couldn't change it even by modifying the file directly (I wrote "DAs"
> into the file, but then it didn't work anymore at all).
>
> Seems as if I'm always getting a lowercase abbreviation, no matter how
> I'm defining my abbreviations.
>
> Could anyone please give me any hint on how to change this behaviour?
>
> Thanks a lot in advance!
I think that's just how abbrevs work. But `define-abbrev' permits a
function to handle abnormal expansions:
(defmacro define-literal-abbrev (table name expansion &optional count system-flag)
`(define-abbrev ,table ,(downcase name) 'literal-abbrev
(lambda ()
(let (case-fold-search
(start (- (point) ,(length name))))
(when (looking-back (regexp-quote ,name) start)
(delete-region start (point))
(insert ,expansion))))
,count ,system-flag))
(define-literal-abbrev global-abbrev-table "DAs" "Das")
...and save the abbrev-table.
-ap
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problems with the capitalization in Word Abbreviation Mode
2008-10-06 13:12 ` Andreas Politz
@ 2008-10-06 14:31 ` Hans-Christian Mick
2008-10-06 16:53 ` Andreas Politz
0 siblings, 1 reply; 7+ messages in thread
From: Hans-Christian Mick @ 2008-10-06 14:31 UTC (permalink / raw)
To: help-gnu-emacs
That's just what I wanted, thanks a lot!
I've just pasted into my abbrev-defs-file. Although this lisp-stuff
looks really complicated to me... How long does it take to learn this
stuff?
Am I right in thinking that in order to add more of these literal-
abbrevs to my abbrev-defs file I should have to write something like
this:
(define-literal-abbrev global-abbrev-table (
("DAs" "Das")
("DIe" "Die")
("WEr" "Wer")
))
Although I have to admit that now it sounds like the theme of the
German Sesame-Street...:)
Thanks again!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problems with the capitalization in Word Abbreviation Mode
@ 2008-10-06 16:06 martin rudalics
0 siblings, 0 replies; 7+ messages in thread
From: martin rudalics @ 2008-10-06 16:06 UTC (permalink / raw)
To: help-gnu-emacs
> A typo that happens to me rather often is that for example I'm typing
> "DAs" instead of "Das" at the beginning of a sentence.
I have tried to handle that with the option `speck-auto-correct-case',
see
http://www.emacswiki.org/cgi-bin/wiki/SpeckMode
martin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problems with the capitalization in Word Abbreviation Mode
2008-10-06 14:31 ` Hans-Christian Mick
@ 2008-10-06 16:53 ` Andreas Politz
0 siblings, 0 replies; 7+ messages in thread
From: Andreas Politz @ 2008-10-06 16:53 UTC (permalink / raw)
To: help-gnu-emacs
Hans-Christian Mick wrote:
>
> That's just what I wanted, thanks a lot!
>
> I've just pasted into my abbrev-defs-file. Although this lisp-stuff
> looks really complicated to me... How long does it take to learn this
> stuff?
>
Mh, you shouldn't paste it in this file. Paste it in the scratch buffer
, eval* it and make emacs save the abbrevs (e.g. by C-x s). Now you
can delete the code.
There is an introduction to elisp for non-programmers in the info files.
(info "(eintr)")
*Place point behind the last paren and type C-x C-e.
> Am I right in thinking that in order to add more of these literal-
> abbrevs to my abbrev-defs file I should have to write something like
> this:
>
> (define-literal-abbrev global-abbrev-table (
> ("DAs" "Das")
> ("DIe" "Die")
> ("WEr" "Wer")
> ))
>
No, but maybe a command is more convenient. Note
the updated function.
(defun define-literal-abbrev (table name expansion &optional count system-flag)
(define-abbrev table (downcase name) 'literal-abbrev
`(lambda ()
(let (case-fold-search
(start (- (point) ,(length name))))
(when (looking-back ,(regexp-quote name) start)
(delete-region start (point))
(insert ,expansion))))
count system-flag))
(defun add-literal-global-abbrev (name expansion)
(interactive "MAbbrev : \nMExpansion : ")
(define-literal-abbrev global-abbrev-table name expansion))
> Although I have to admit that now it sounds like the theme of the
> German Sesame-Street...:)
>
> Thanks again!
-ap
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problems with the capitalization in Word Abbreviation Mode
2008-10-06 8:12 Problems with the capitalization in Word Abbreviation Mode Hans-Christian Mick
2008-10-06 13:12 ` Andreas Politz
@ 2008-10-07 4:06 ` Xah
1 sibling, 0 replies; 7+ messages in thread
From: Xah @ 2008-10-07 4:06 UTC (permalink / raw)
To: help-gnu-emacs
another way to fix letter-case typo problem is to use one of emacs
commands to change letter case.
There are capitalize-word, downcase-word, upcase-word. Type C-h
‹function-name› to see their default keybindings.
There are also several varieties:
(upcase obj)
(upcase-word 3)
(upcase-region beg end)
(upcase-initials obj)
(upcase-initials-region beg end)
(capitalize obj)
(capitalize-word n)
(capitalize-region myStartPos myEndPos)
(downcase)
(downcase-word arg)
(downcase-region beg end)
One problem with them is that you need to move your cursor to the
beginning of the word first. For example, if your cursor is on the “A”
In “THat”, And You Call downcase-word, but it doesn't do anything
because it only start at the cursor point to end of word.
It would be nice if it'll just automatically perform the operation on
the whole word as a region.
Another problem is that it only performs one specific operation as
opposed to considering the final result. For example, if you have
“oncE upon a time ...”, and you select the whole sentence and call
upcase-initials-region, it becomes “OncE Upon A Time ...”, but the
capital E is not automatically lowered.
Also, most of these commands have a “-word” and “-region” version...
great for precision in elisp programing but not smart as user
commands. It would be nice if a region is active, then automatically
do the command on the region, else the current word. (emacs is this
way because technically, a “region” always exists. The modern concept
of text selection (with highlighting) didn't come to emacs until it
had transient-mark-mode, along with the complexity of “mark-active”.
Things would be much simpler if emacs adopted transient-mark-mode by
default.)
I've combined these into one function and i think fixed the above
usability issues:
(defun toggle-letter-case ()
"Toggle the current word or region's letter case.
Toggles from 3 cases: upper case, lower case, title case,
in that order.
Title case means upcase first letter of each word."
(interactive)
(save-excursion
(let (pt pos1 pos2 cap1p cap2p (deactivate-mark nil) (case-fold-search
nil))
(setq pt (point))
(if (and transient-mark-mode mark-active)
(setq pos1 (region-beginning)
pos2 (region-end))
(setq pos1 (car (bounds-of-thing-at-point 'word))
pos2 (cdr (bounds-of-thing-at-point 'word))))
(goto-char pos1)
(setq cap1p (looking-at "[A-Z]"))
(goto-char (1+ pos1))
(setq cap2p (looking-at "[A-Z]"))
(cond
((and (not cap1p) (not cap2p)) (upcase-initials-region pos1 pos2))
((and cap1p (not cap2p)) (upcase-region pos1 pos2) )
((and cap1p cap2p) (downcase-region pos1 pos2) )
(t (downcase-region pos1 pos2) )
)
)
)
)
and recently assigned it a single shortcut. See
http://xahlee.org/emacs/ergonomic_emacs_keybinding.html
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problems with the capitalization in Word Abbreviation Mode
[not found] <mailman.381.1223309323.25473.help-gnu-emacs@gnu.org>
@ 2008-10-07 18:35 ` Xah
0 siblings, 0 replies; 7+ messages in thread
From: Xah @ 2008-10-07 18:35 UTC (permalink / raw)
To: help-gnu-emacs
On Oct 6, 9:06 am, martin rudalics <rudal...@gmx.at> wrote:
> > A typo that happens to me rather often is that for example I'm typing
> > "DAs" instead of "Das" at the beginning of a sentence.
>
> I have tried to handle that with the option `speck-auto-correct-case',
> see
>
> http://www.emacswiki.org/cgi-bin/wiki/SpeckMode
>
> martin
Thank you very much! I've been desiring for such a feature. Very well
done.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-10-07 18:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-06 8:12 Problems with the capitalization in Word Abbreviation Mode Hans-Christian Mick
2008-10-06 13:12 ` Andreas Politz
2008-10-06 14:31 ` Hans-Christian Mick
2008-10-06 16:53 ` Andreas Politz
2008-10-07 4:06 ` Xah
-- strict thread matches above, loose matches on Subject: below --
2008-10-06 16:06 martin rudalics
[not found] <mailman.381.1223309323.25473.help-gnu-emacs@gnu.org>
2008-10-07 18:35 ` Xah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).