capitalised in 'abbrev_defs'?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

capitalised in 'abbrev_defs'?

Sharon Kimble-2

Whenever I save a new addition to 'abbrev_defs' that is capitalised it
is *always* saved in lower case. How do I get it to save as capitalised
please? I've googled but haven't found any solution to the problem.

Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
DrugFacts = https://www.drugfacts.org.uk 
Debian 9.0, fluxbox 1.3.5-2, emacs 25.1.1, org-mode 9.0.9

signature.asc (847 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: capitalised in 'abbrev_defs'?

Emanuel Berg-4
Sharon Kimble wrote:

> Whenever I save a new addition to
> 'abbrev_defs' that is capitalised it is
> *always* saved in lower case. How do I get it
> to save as capitalised please?

See ‘:case-fixed’ in

    (info "(elisp) Abbrev Properties")

The reason this isn't there by default is to
have a more (?) intelligent system that will
capitalize the abbrev expansion differently for
the same abbrev input, depending on the
capitalization of the input.

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: capitalised in 'abbrev_defs'?

Sharon Kimble-2
Emanuel Berg <[hidden email]> writes:

> Sharon Kimble wrote:
>
>> Whenever I save a new addition to
>> 'abbrev_defs' that is capitalised it is
>> *always* saved in lower case. How do I get it
>> to save as capitalised please?
>
> See ‘:case-fixed’ in
>
>     (info "(elisp) Abbrev Properties")
>
> The reason this isn't there by default is to
> have a more (?) intelligent system that will
> capitalize the abbrev expansion differently for
> the same abbrev input, depending on the
> capitalization of the input.
Okay, thanks for this.

This is my main block of code that initialises abbrev_defs -

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp
;; (setq abbrev-file-name (concat *my-emacs-lib-dir* "abbrev_defs.el"))
; I define *my-emacs-lib-dir* in my .emacs; see that section for details
    ;; (setq abbrev-file-name (locate-user-emacs-file "abbrev_defs"))
    ;; (unless (file-exists-p abbrev-file-name)
    ;;   (with-temp-buffer (write-file abbrev-file-name)))

(setq abbrev-file-name             ;; tell emacs where to read abbrev
        "/home/boudiccas/.emacs.d/abbrev_defs")    ;; definitions from...

;; (setq abbrev-file-name ("abbrev_defs"))
    (defconst modi/abbrev-hooks '(verilog-mode-hook
                                  emacs-lisp-mode-hook
                                  org-mode-hook)
      "List of hooks of major modes in which abbrev should be enabled.")

    (defun modi/turn-on-abbrev-mode ()
      "Turn on abbrev only for specific modes."
      (interactive)
      (dolist (hook modi/abbrev-hooks)
        (add-hook hook #'abbrev-mode)))

    (defun modi/turn-off-abbrev-mode ()
      "Turn off abbrev only for specific modes."
      (interactive)
      (dolist (hook modi/abbrev-hooks)
        (remove-hook hook #'abbrev-mode)))

    (setq save-abbrevs 'silently) ; silently save abbrevs on quitting emacs

    (modi/turn-on-abbrev-mode)
    (quietly-read-abbrev-file) ; reads the abbreviations file on startup


(read-abbrev-file abbrev-file-name t)
(setq dabbrev-case-replace nil)  ; Preserve case when expanding
(setq abbrev-mode t)
#+end_src
[2015-12-22 Tue 10:27]
[2015-12-26 Sat 05:37]
[2017-01-17 Tue 10:38]

heavily influenced by kaushalmodi
--8<---------------cut here---------------end--------------->8---

And this is my main block of code which uses abbrev_defs -

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp
(define-key ctl-x-map "\C-i"
  #'endless/ispell-word-then-abbrev)

(defun endless/ispell-word-then-abbrev (p)
  "Call `ispell-word', then create an abbrev for it.
With prefix P, create local abbrev. Otherwise it will
be global.
If there's nothing wrong with the word at point, keep
looking for a typo until the beginning of buffer. You can
skip typos you don't want to fix with `SPC', and you can
abort completely with `C-g'."
  (interactive "P")
  (let (bef aft)
    (save-excursion
      (while (if (setq bef (thing-at-point 'word))
                 ;; Word was corrected or used quit.
                 (if (ispell-word nil 'quiet)
                     nil ; End the loop.
                   ;; Also end if we reach `bob'.
                   (not (bobp)))
               ;; If there's no word at point, keep looking
               ;; until `bob'.
               (not (bobp)))
        (backward-word))
      (setq aft (thing-at-point 'word)))
    (if (and aft bef (not (equal aft bef)))
        (let ((aft (downcase aft))
              (bef (downcase bef)))
          (define-abbrev
            (if p local-abbrev-table global-abbrev-table)
            bef aft)
          (message "\"%s\" now expands to \"%s\" %sally"
                   bef aft (if p "loc" "glob")))
      (user-error "No typo at or before point"))))

(setq save-abbrevs 'silently)
(setq-default abbrev-mode t)
#+end_src
[2016-02-14 Sun 18:15]
[2017-01-17 Tue 13:37]

http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html
--8<---------------cut here---------------end--------------->8---

So how do I 'turn on' case-fixed please? Would it be something like -

--8<---------------cut here---------------start------------->8---
(setq abbrev-mode case-fixed t)
--8<---------------cut here---------------end--------------->8---

Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
DrugFacts = https://www.drugfacts.org.uk 
Debian 9.0, fluxbox 1.3.5-2, emacs 25.1.1, org-mode 9.0.9

signature.asc (847 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: capitalised in 'abbrev_defs'?

Kaushal Modi
On Thu, Jul 27, 2017, 6:07 AM Sharon Kimble <[hidden email]>
wrote:

> Emanuel Berg <[hidden email]> writes:
>
>     (defconst modi/abbrev-hooks '(verilog-mode-hook
>                                   emacs-lisp-mode-hook
>                                   org-mode-hook)
>       "List of hooks of major modes in which abbrev should be enabled.")
>

You can customize this to only the major modes where you want abbrev-mode
to be enabled. These values are specific to my use case.

>
heavily influenced by kaushalmodi
>

Thanks for the attribute. I wasn't expecting any so I was surprised :)

(setq save-abbrevs 'silently)
>

This is repeating (based on the snippet you pasted above).

(setq-default abbrev-mode t)
>

This would enable abbrev-mode globally. So the per-major-mode abbrev-mode
enabling above would be redundant. Also I wouldn't enable any minor mode by
just setting the mode variable. The canonical way would be to use
(global-FOO-mode 1) or (global-FOO-mode) if global-FOO-mode is defined.

So how do I 'turn on' case-fixed please? Would it be something like -
>
> --8<---------------cut here---------------start------------->8---
> (setq abbrev-mode case-fixed t)
> --8<---------------cut here---------------end--------------->8---
>

Above will not work.

I haven't yet tried but check out the solution someone posted here:
https://stackoverflow.com/a/15315076/1219634

> --

Kaushal Modi
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: capitalised in 'abbrev_defs'?

Emanuel Berg-4
In reply to this post by Sharon Kimble-2
Sharon Kimble wrote:

> So how do I 'turn on' case-fixed please?
> Would it be something like -
>
> (setq abbrev-mode case-fixed t)

I would do it on a per-abbrev basis, but it
seems it can be done globally or for each
abbrev tables with the code that is in the URL
Kaushal Modi posted.

Note that this might break expected behavior
from your other abbrevs depending on how you
are used to use them. But it is not like it is
dangerous to try or anything.

Keep it up :)

--
underground experts united
http://user.it.uu.se/~embe8573


Loading...