1

With my Emacs 26.1 on my 10.13.6 Mac, I want Emacs to systemically open my file located at /Users/ewandelanoy/Documents/html_files/Printable/latinized_agreda2.txt with the mac-roman-mac encoding, without changing Emacs' normal behavior on other files.

Following the advice given in this answer, I added the line (modify-coding-system-alist "/Users/ewandelanoy/Documents/html_files/Printable/latinized_agreda2.txt" 'mac-roman-mac) to my init.el file, but it seems that this is incorrect since when I restart emacs I get the following (somewhat unclear) error message :

Warning (initialization): An error occurred while loading ‘/Users/ewandelanoy/.emacs.d/init.el’:

Wrong number of arguments: #[(target-type regexp coding-system) \306>\204�\307\310"\210 ;\204 �\311=\203�   \250\204 �\307\312  "\210
9\2036�\313
!\204@�\314
!\210
\211B\202@�\314
@!\210\314
A!\210\315\267\202v�\316    "\211\203U�
\241\202\�  
BB\211)\207\316 
"\211\203m�
\241\202t�  
B
B\211)\207\316  "\211\203\206�
\241\202\217�   
BB\211)\207 [target-type regexp coding-system file-coding-system-alist slot process-coding-system-alist (file process network) error Invalid target type: %s network Invalid regular expression: %s fboundp check-coding-system #s(hash-table size 2 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (file 70 process 94)) assoc network-coding-system-alist] 4 2267173], 2

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

When I start Emacs with the --debug-init option as advised, I get the following error message :

Debugger entered--Lisp error: (void-function global-linum-mode)
  (global-linum-mode t)
  eval-buffer(#<buffer  *load*<2>> nil "/Users/ewandelanoy/Documents/Bash_scripts/init.el" nil t)  ; Reading at buffer posit$
  load-with-code-conversion("/Users/ewandelanoy/Documents/Bash_scripts/init.el" "/Users/ewandelanoy/Documents/Bash_scripts/i$
  load("~/Documents/Bash_scripts/init.el")
  eval-buffer(#<buffer  *load*> nil "/Users/ewandelanoy/.emacs.d/init.el" nil t)  ; Reading at buffer position 42
  load-with-code-conversion("/Users/ewandelanoy/.emacs.d/init.el" "/Users/ewandelanoy/.emacs.d/init.el" t t)
  load("/Users/ewandelanoy/.emacs.d/init" t t)
  #[nil "^H\205\276^@   \306=\203^Q^@\307^H\310Q\202A^@ \311=\2033^@\312\307\313\314#\203#^@\315\202A^@\312\307\313\316#\203$
  command-line()
  normal-top-level()

The second error message is not really any clearer than the first. What did I do wrong ?

1

You didn't do anything wrong, I did: I forgot an argument to the function. Let me at least partially explain the error message.

In your case, you already know that the error has to do with the call to modify-coding-system-alist, since your init file broke when you added that line. The error message is:

Wrong number of arguments: #[(target-type regexp coding-system) (gobbledygook omitted)], 2

This means that the function expects the argument list (target-type regexp coding-system), but you passed 2 arguments. This function requires exactly three arguments.

You can see the documentation of the function in the manual, or online in Emacs by navigating to the function call and pressing f1 f RET or C-h f RET. This gives the same information about the parameter list, plus some documentation that explains what each parameter is. Given the call

(modify-coding-system-alist "/Users/ewandelanoy/Documents/html_files/Printable/latinized_agreda2.txt" 'mac-roman-mac)

it's fairly apparent that "/Users/ewandelanoy/Documents/html_files/Printable/latinized_agreda2.txt" fits the regexp argument and 'mac-roman-mac fits the coding-system argument, so what's missing is the target-type argument. According to the help, target-type must be one of the symbols file, process or network. You're trying to affect what happens when you open a file, so the correct call is

(modify-coding-system-alist 'file "/Users/ewandelanoy/Documents/html_files/Printable/latinized_agreda2.txt" 'mac-roman-mac)

If you didn't know that the problem was in the call modify-coding-system-alist, how could you figure it out? Unfortunately, Emacs doesn't show the function name in the error message, because the error is detected too late, at a point where the Lisp interpreter has the code but has forgotten the function name. The gobbledygook in the error message is a rendition of the compiled bytecode. With --debug-init, you can see where the error is coming from. The information is buried in a lot of incomprehensible detail, but it's there. The relevant line is

eval-buffer(#<buffer  *load*> nil "/Users/ewandelanoy/.emacs.d/init.el" nil t)  ; Reading at buffer position 42

Look for the line containing the path to your init file. It's the line above the call to load-with-code-conversion. It has the annotation Reading at buffer position … which is the character number where the error was detected. Open your init file and navigate to this position with M-g c 42 RET (goto-char command).

In the backtrace, function calls are hyperlinked to the definition of the function. Unfortunately, there's no hyperlink for the place where the function is called (even though Emacs did know the location of the call), so you have to navigate there manually.

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.