4

Why can't I directly set csv-mode variables like that:

(setq csv-separators '(";" "\t"))
(setq csv-field-quotes '("\"" "'"))

and I'm forced to set it like that:

(custom-set-variables '(csv-separators '(";" "\t")))
(custom-set-variables '(csv-field-quotes '("\"" "'")))

?

So, with this init file for csv-mode, my personnal settings are taken into account:

(require 'csv-mode)

(defun my/csv-mode-set-properties ()
  "Set properties for editing CSV files."
  (custom-set-variables '(csv-separators '(";" "\t")))
  (custom-set-variables '(csv-field-quotes '("\"" "'")))
  (custom-set-variables '(csv-align-padding 2))
  (custom-set-variables '(csv-header-lines 1)))

(add-hook 'csv-mode-hook 'my/csv-mode-set-properties)

(provide 'init-csv-mode)

but not with that:

(require 'csv-mode)

(defun my/csv-mode-set-properties ()
  "Set properties for editing CSV files."
  (setq csv-separators '(";" "\t"))
  (setq csv-field-quotes '("\"" "'"))
  (setq csv-align-padding 2)
  (setq csv-header-lines 1))

(add-hook 'csv-mode-hook 'my/csv-mode-set-properties)

(provide 'init-csv-mode)
6
  • 1
    Please explain what doesn't work when you use setq but does work when you use custom-set-variables. – Dan Jul 18 '16 at 13:02
  • The assignment itself. Variables values are not changed with setq, but they are with custom-set-variables. – P.-A. Jul 18 '16 at 13:06
  • 1
    setq has no problem setting the values on my machine. Please provide a complete working example. – Dan Jul 18 '16 at 13:12
  • @Dan I changed my post : the last code section is the working example. – P.-A. Jul 18 '16 at 13:32
  • 1
    Start Emacs without your init file (emacs -Q) and try the setqs. Query the variable value with C-h v csv-separators. If everything works (and it should), recursively bisect your init file (commenting out successive halves) to find out what's causing the problem. – Dan Jul 18 '16 at 14:30
4

Don't use the csv-hook:

(setq csv-separators '(";" "\t"))
(setq csv-field-quotes '("\"" "'"))
(setq csv-align-padding 2)
(setq csv-header-lines 1)
(require 'csv-mode)
(provide 'init-csv-mode)

Works

8
  • Unfortunatly I already tried, and it doesn't work... But I don't understand why. – P.-A. Jul 18 '16 at 14:06
  • Do you take this version of csv mode ?: github.com/emacsmirror/csv-mode – djangoliv Jul 18 '16 at 14:48
  • No, the next one: 1.6 – P.-A. Jul 18 '16 at 14:55
  • Can't reproduce with 1.6 too. The problem is somewhere else in your init.el – djangoliv Jul 18 '16 at 15:01
  • 2
    Any reason you don't use the version in GNU ELPA? AFAIK that's the only half-maintained version. Feel free to submit bug reports for that version using M-x report-emacs-bug. – Stefan Jul 19 '16 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.