On 2013-02-09 11:38, Mads Jensen wrote:
> I previously sent this file, and have modified it slightly, because it
> wasn't working.  For some bizarre reason, it doesn't work using
> `TeX-argument-insert' but a normal `insert' + format works.  If someone
> can give a good explanation why this is, I'd appreciate it.  The `fmt'
> variable is a string, so the error doesn't make any sense in my mind.
> 
> 2013-02-09  Mads Jensen  <[email protected]>
> 
>       * style/enumerate.el: New style.

There were two things I neglected in the first submission; one was the
check to see that the length of fmt is non-zero, and the other was 1 in
the plus calculation to find the correct position to insert the
argument. I tested it, and it works nicely :) I'm still interested in
knowing why TeX-insert-argument does not work, since it would make the
expression simpler.
-- 
Med Venlig Hilsen / Kind Regards,
Mads Jensen
Rubinsteinsvej 31,st.th
DK-2450 Kbh. SV
Denmark
+45 6168 8518
My brain is my second favorite organ.
      -- Woody Allen
;;; enumerate.el --- AUCTeX style for `enumerate.sty'

;; Copyright (C) 2013 Free Software Foundation, Inc.

;; Author: Mads Jensen <[email protected]>
;; Maintainer: [email protected]
;; Keywords: tex

;; This file is part of AUCTeX.

;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Commentary:

;; This file adds support for `enumerate.sty'

;;; Code:

(TeX-add-style-hook
 "enumerate"
 (lambda ()
   ;; enumerate just offers the oppertunity to modify how the
   ;; enumeration in the enumerate environment takes place
   (add-hook 'LaTeX-after-insert-env-hooks
             'LaTeX-enumerate-after-insert-env-hook)))

(defun LaTeX-enumerate-after-insert-env-hook (env start end)
  "Hook to insert the formatting string for the enumerate environment"
  (when (string-equal env "enumerate")
    (let ((fmt
           (read-string
            (TeX-argument-prompt
             t
             "Formatting string for the environment (tokens: A, a, I, i or 1)"
                                 nil))))
      (when (not (zerop (string-width fmt)))
        (save-excursion ;; so the \\item is put in the right place
          (goto-char (+ 1 start (length (concat "\begin{" env "}"))))
          ;; for some reason, TeX-argument-insert barfs about char-or-string-p
          ;; so this is the best alternative ...
          (if (not (zerop (length fmt)))
              (insert (format "%s" (concat LaTeX-optop fmt LaTeX-optcl)))))))))

(defvar LaTeX-enumerate-package-options nil
  "Package options for enumerate.")

;; enumerate.el ends here

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
auctex-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to