nim-lang / nim-mode

An emacs major mode for the Nim programming language
138 stars 46 forks source link

Fix nil buffer-file-name in doc config example #233

Closed vincent-picaud closed 4 years ago

vincent-picaud commented 4 years ago

In README.md there is a configuration code example:

  ;; Make files in the nimble folder read only by default.
  ;; This can prevent to edit them by accident.
  (when (string-match "/\.nimble/" buffer-file-name) (read-only-mode 1))

However this line is problematic when buffer-file-name returns nil.

In peculiar if you try to html-export (C-c C-e h o) this org-mode file:

#+begin_src nim
echo "Hello"
#+end_src

#+RESULTS:
: Hello

you get this error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("/.nimble/" nil)
  (if (string-match "/.nimble/" buffer-file-name) (progn (read-only-mode 1)))
  (when (string-match "/.nimble/" buffer-file-name) (read-only-mode 1))

This PR fixes this by replacing:

(when (string-match "/\.nimble/" buffer-file-name) (read-only-mode 1))

by

(when (string-match "/\.nimble/" (or (buffer-file-name) "")) (read-only-mode 1))

that handles the case where the buffer is not associated to a file.

krux02 commented 4 years ago

CI failure unrelated. This PR can be merged. You get my approval. But as far as I know there is nobody actively maintaining this repositiory.

vincent-picaud commented 4 years ago

Ok, thank you for the feed back. I am using this repository and I am happy with it :)