all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* (local) abbrev injective and other problems, capitalization
@ 2018-07-03  7:25 Uwe Brauer
  2018-07-03 22:01 ` Stefan Monnier
  2018-07-10  4:06 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Uwe Brauer @ 2018-07-03  7:25 UTC (permalink / raw)
  To: emacs-devel


Hi 

I think I brought up that subject some time ago but it seems it was
never really solved, even not in git master from June.


Here is the problem (I am concentrating on local
abbrev, but I don't think that is important).


I would like to have to following expansions:

A

  nacion --> nacíon
  Nacion --> Nacíon

And if explicitly defined

B
  nacion --> Nacíon
  Nacion --> nacíon

But what I don't want is that when A is defined, B is implied.

I mainly define abbrev via flyspell, but I was surprised to find that if
I type

 Nacion M-x inserve-add-mode-abbrev Nacíon enter

But then nacíon is expanded to Nacíon 

That is wrong!


So there seems something wrong with capitalisation. Looking at the
corresponding local abbrev table I see.


"nacion"       4    "Nacíon"

Which is wrong it should have been 

"Nacíon"      4 "Nacíon"


What do I miss?

Regards

Uwe Brauer 




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

* Re: (local) abbrev injective and other problems, capitalization
  2018-07-03  7:25 (local) abbrev injective and other problems, capitalization Uwe Brauer
@ 2018-07-03 22:01 ` Stefan Monnier
  2018-07-04  6:27   ` Uwe Brauer
  2018-07-10  4:06 ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2018-07-03 22:01 UTC (permalink / raw)
  To: emacs-devel

> What do I miss?

abbrevs are case-insensitive by default, as suggested by the following
in `define-abbrev`s docstring (and specified more clearly elsewhere,
most likely):

    [...]
    NAME must be a string, and should be lower-case.
    [...]
    - `:case-fixed': non-nil means that abbreviations are looked up without
      case-folding, and the expansion is not capitalized/upcased.
    [...]


-- Stefan




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

* Re: (local) abbrev injective and other problems, capitalization
  2018-07-03 22:01 ` Stefan Monnier
@ 2018-07-04  6:27   ` Uwe Brauer
  2018-07-04 13:01     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Brauer @ 2018-07-04  6:27 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 949 bytes --]

>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

   >> What do I miss?
   > abbrevs are case-insensitive by default, as suggested by the following
   > in `define-abbrev`s docstring (and specified more clearly elsewhere,
   > most likely):

Well I would call it *partially case-insensitive*

Because if I define 

 nacion -->  nacíon

Then 

Nacion is *not* expanded to Nacion 

But if I try to define 

 Nacion --> Nación

It does not work. Very confusing.

So it seems that   :case-fixed is the solution. But how do I use is for
inverse-add-mode-abbrev and friends?

The docstring of that function  does not say anything about this variable.

Maybe one should define a new variable, say

add-abbrev-case-fixed

If it is t, case-fixed is added to the abbrev table and nil would be the
standard behaviour. Our maybe this is already implemented. Any pointer
would be welcome.

Thanks 

Uwe 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]

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

* Re: (local) abbrev injective and other problems, capitalization
  2018-07-04  6:27   ` Uwe Brauer
@ 2018-07-04 13:01     ` Stefan Monnier
  2018-07-05 10:15       ` Uwe Brauer
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2018-07-04 13:01 UTC (permalink / raw)
  To: emacs-devel

> So it seems that :case-fixed is the solution.  But how do I use is for
> inverse-add-mode-abbrev and friends?

You'll need to tweak the code and/or write your own, I'm afraid.

Patches in this area are very welcome: when I implemented those
features, I didn't touch the UI part, so they're currently only
used/usable from Elisp.


        Stefan




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

* Re: (local) abbrev injective and other problems, capitalization
  2018-07-04 13:01     ` Stefan Monnier
@ 2018-07-05 10:15       ` Uwe Brauer
  0 siblings, 0 replies; 6+ messages in thread
From: Uwe Brauer @ 2018-07-05 10:15 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2325 bytes --]

>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

   >> So it seems that :case-fixed is the solution.  But how do I use is for
   >> inverse-add-mode-abbrev and friends?

   > You'll need to tweak the code and/or write your own, I'm afraid.

Ok. I am not really using inverse-add-mode-abbrev but I use the abbrev
via flyspell. Flyspell allows you to insert a correction either in the
local (which is my case) or in the global abbrev table. 

I have even written a small package my own, which I might put some day
in MELPA, which generalise this mechanism to various languages. Most
likely this is not very elegant but for each language there exists a
minor mode with its associated local abbrev table (right now the package
contains 5 language but it could be generalised). The point which is a
bit delicate is, that if you switch one minor mode on, you have to make
sure that the others are off.

So here is a short example
(define-abbrev-table 'francais-minor-mode-abbrev-table '(	 ;Version:1.2
     ("tx" "text" nil 0)
     ))

(defvar francais-minor-mode-syntax-table nil
  "Syntax table used while in francais  mode.")

(define-minor-mode francais-minor-mode	
    nil nil nil nil
    (setq local-abbrev-table
          (if francais-minor-mode
              francais-minor-mode-abbrev-table)))


And some function which are not relevant here.

In any case, the code most relevant here is the following 

(defun flyspell-define-abbrev (name expansion)
  (let ((table (flyspell-abbrev-table)))
    (when table
      (define-abbrev table (downcase name) expansion ))))


So first the phrase to be abbrev-expanded is downcased and then defined.


My first naive approach was this


(define-abbrev table (downcase name) expansion nil :case-fixed nil))))(defun flyspell-define-abbrev (name expansion)
  (let ((table (flyspell-abbrev-table)))
    (when table
      (define-abbrev table (downcase name) expansion nil :case-fixed nil))))

But it did not work.

I then tried 

(abbrev-table-put text-mode-abbrev-table :case-fixed t)

Or 
(abbrev-table-put francais-minor-mode-syntax-table :case-fixed t)

But it did not help. The problem described persisted. Any help would be
appreciate because right now I don't know where to start even.

Uwe 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]

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

* Re: (local) abbrev injective and other problems, capitalization
  2018-07-03  7:25 (local) abbrev injective and other problems, capitalization Uwe Brauer
  2018-07-03 22:01 ` Stefan Monnier
@ 2018-07-10  4:06 ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2018-07-10  4:06 UTC (permalink / raw)
  To: emacs-devel

> I would like to have to following expansions:
>
> A
>
>   nacion --> nacíon
>   Nacion --> Nacíon

Barring bugs, this is what you should be getting by default when you
define a single "nacion --> nacíon" abbrev [which language is that?]

> And if explicitly defined
>
> B
>   nacion --> Nacíon
>   Nacion --> nacíon

These ones require `:case-fixed t` but they also require that you don't
`downcase` the string before passing it to `define-abbrev`, of course.


        Stefan




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

end of thread, other threads:[~2018-07-10  4:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-03  7:25 (local) abbrev injective and other problems, capitalization Uwe Brauer
2018-07-03 22:01 ` Stefan Monnier
2018-07-04  6:27   ` Uwe Brauer
2018-07-04 13:01     ` Stefan Monnier
2018-07-05 10:15       ` Uwe Brauer
2018-07-10  4:06 ` Stefan Monnier

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.