help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Abbrevs and Comments


From: Roberto Huelga
Subject: Re: Abbrevs and Comments
Date: Sun, 26 Jan 2003 18:44:35 +0100


El lunes, 13 ener, 2003, a las 13:09 Europe/Madrid, Roberto Huelga escribió:

Hello, and happy new year to every body (my first mail of the year).

I recently modify my .emacs file to make use of abbrev and skeletons in c-mode and c++-mode. I make that "if" expands to "if() { }" and all is prefect. But When I'm writing a comment or a literal the abbrev expands too. Is there a automatic way to don't expand in these situations?.

I finally develop a automatic way, may be not optimal but work great in my computer. I look the face in the current point and I modify the local-abbrev-table in consequence. Insert this in .emacs to try it

(add-hook 'pre-abbrev-expand-hook 'abbrev-literal-test)
(defun abbrev-literal-test()
  (let* ((face (get-text-property (point) 'face )))
    (if (or (equal face 'font-lock-comment-face)
            (equal face 'font-lock-string-face)
            (equal face 'font-lock-warning-face))
        (setq local-abbrev-table nil)
      (setq local-abbrev-table (eval
                                (car
                                 (read-from-string
                                  (format "%s-abbrev-table" major-mode)))))
      )))

        If someone optimise this or found a better way, please tell me.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]