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)
P.-A.
  • 115
  • 10
  • 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
  • No need the use csv-hook here. – djangoliv Jul 18 '16 at 13:37
  • 1
    Start Emacs without your init file (`emacs -Q`) and try the `setq`s. 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

1 Answers1

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

djangoliv
  • 3,169
  • 16
  • 31
  • 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 ?: https://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
  • After searching a while I found a working solution (with both 1.5 and 1.6), but I do not understand why. I simply put `(require 'csv-mode)` at the end of your proposal, just before the `provide`. Do you have any idea about why does it work ? – P.-A. Jul 18 '16 at 15:25
  • No it should work in the both cases – djangoliv Jul 19 '16 at 07:03
  • 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
  • @djangoliv If you put the `require` at the end of your code I can accept it to close the question. – P.-A. Jul 22 '16 at 21:03