2

I'm having trouble using:

(add-hook ’before-save-hook #’gofmt-before-save)

This is supposed to format the go code before saving. The error I get is:

Debugger entered--Lisp error: (invalid-read-syntax "#")
  read(#<buffer  *load*>)
  eval-buffer(#<buffer  *load*> nil "/home/bennett/.emacs" nil t)  ; Reading at buffer position 774
  load-with-code-conversion("/home/bennett/.emacs" "/home/bennett/.emacs" t t)
  load("~/.emacs" t t)
  #f(compiled-function () #<bytecode 0x258a41>)()
  command-line()
  normal-top-level()

The only "weird" thing I'm doing is using packages to load go-mode, rather than doing it manually. The code is here:

(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")))


;; Broken.  Which is weird, since it came straight from the *Help* for go-mode

(add-hook ’before-save-hook #’gofmt-before-save)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(diff-switches "-u")
 '(package-selected-packages (quote (go-mode)))
 '(send-mail-function (quote mailclient-send-it))
 '(show-paren-mode t))

;;; uncomment for CJK utf-8 support for non-Asian users
;; (require 'un-define)
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "DejaVu Sans Mono" :foundry "PfEd" :slant normal :weight normal :height 90 :width normal)))))

Any thoughts? I'm pretty far out of my element, here. I tried it without the # character, thinking it was a typo. I get a different error, but it still doesn't work.

4

Use a straight quote ('), not a typographically correct one (). This goes for programming in general, nearly all languages out there stick to the ASCII character set. Emacs helpfully displays the quotes in the typographically correct way, this breaks copy-pasting them into your own code.

  • Ye Gads. I would have never seen that. How do I know if a file is Unicoded? How can I un-unicode it? Thanks. – Erik Bennett Mar 23 at 19:05
  • This has nothing to do with Unicode. ASCII is perfectly compatible with UTF-8, so a file using regular quotes can be displayed in a UTF-8-coded buffer just fine. Consider switching to a font that makes the curliness of the quote more pronounced. – wasamasa Mar 23 at 19:15
  • I didn't think there was an ASCII character for the typographically correct one. In the file it's written as 0342 0200 0231, which is, I think UTF-8 (Unicode Transformation Format). But your suggestion is sound. Also, I was never expecting UTF-8 encoding of my .emacs file (I learned emacs when it was emacs 18.something). Thanks! As I said, I never would have seen that; I didn't know to look. – Erik Bennett Mar 23 at 19:27
6

;; Broken. Which is weird, since it came straight from the *Help* for go-mode

This almost definitely indicates another case of the recently-introduced (25.1) text-quoting-style default behaviour screwing things up for people in hard-to-notice ways :(

I recommend two things:

  1. Submit a bug report for go-mode. The docstring in question will need to use the syntax \\=' instead of just ' to guarantee that a plain apostrophe is displayed in the *Help* buffer. e.g.:

    (add-hook \\='before-save-hook #\\='gofmt-before-save)
    

    There might well be other instances of this issue in the library, so the other docstrings should be audited as well.

    (Yes, this is ludicrous.)

  2. Customize the text-quoting-style user option, and set its value to 'grave in your own config. In 25.x it's only a defvar, so you'd need to use:

    (setq text-quoting-style 'grave)
    

    As an end-user, this will stop Emacs from making these substitutions in the first place, which prevents such irritating problems from occurring.

    (As an elisp developer, this will prevent you from even noticing if you've unwittingly introduced instances into your own code. Hooray...)

  • Hum, I thought RMS vetoed the whole quotes thing, but maybe that was just about changing docstrings to use curly quotes. – wasamasa Mar 24 at 11:55

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.