Function: LaTeX-listify-package-options

LaTeX-listify-package-options is a byte-compiled function defined in latex.el.

Signature

(LaTeX-listify-package-options OPTIONS)

Documentation

Return a list from a comma-separated string of package OPTIONS.

The input string may include LaTeX comments and newlines.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-listify-package-options (options)
  "Return a list from a comma-separated string of package OPTIONS.
The input string may include LaTeX comments and newlines."
  ;; We jump through all those hoops and don't just use `split-string'
  ;; or the like in order to be able to deal with key=value package
  ;; options which can look like this: "pdftitle={A Perfect Day},
  ;; colorlinks=false"
  (let (opts match start)
    (with-temp-buffer
      (set-syntax-table LaTeX-mode-syntax-table)
      (insert options)
      (newline) ; So that the last entry can be found.
      (goto-char (point-min))
      (setq start (point))
      (while (re-search-forward "[{ ,%\n\r]" nil t)
        (setq match (match-string 0))
        (cond
         ;; Step over groups.  (Let's hope nobody uses escaped braces.)
         ((string= match "{")
          (up-list))
         ;; Get rid of whitespace.
         ((string= match " ")
          (delete-region (1- (point))
                         (save-excursion
                           (skip-chars-forward " ")
                           (point))))
         ;; Add entry to output.
         ((or (string= match ",") (= (point) (point-max)))
          (let ((entry (buffer-substring-no-properties
                        start (1- (point)))))
            (unless (member entry opts)
              (setq opts (append opts (list entry)))))
          (setq start (point)))
         ;; Get rid of comments.
         ((string= match "%")
          (delete-region (1- (point))
                         (line-beginning-position 2)))
         ;; Get rid of newlines.
         ((or (string= match "\n") (string= match "\r"))
          (delete-char -1)))))
    opts))