1

My dotemacsfile looks like the following.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(package-initialize) ;load and activate packages, including auto-complete
(ac-config-default)
(global-auto-complete-mode t)

But when I run the above in a scratch buffer using M-x eval buffer, I get symbol's function definition is void : ac-config-default.

(The error is different from the error I get when I do emacs --init-debug test.R where the init file is in my home directory. I won't show that error in order to not confuse things.)

Drew
  • 75,699
  • 9
  • 109
  • 225
mark leeds
  • 113
  • 6
  • 1
    You should read https://emacs.stackexchange.com/help/formatting - that will allow you to format your posts using Markdown (see my edit e.g.) – NickD Oct 21 '21 at 14:07

1 Answers1

2

You probably just forgot to install the package that ac-config-default comes from. Run M-x list-packages, find the auto-complete package (use C-s to search), and install it.

From the extended discussion, it turns out that it wasn’t clear what the difference between installing and loading a package was. Installing a package means downloading it from the internet, decompressing it, and putting the files where Emacs can find them. Loading a package means that Emacs actually reads some or all of the files, so that you can use what’s in them.

Installing happens once, and is usually done by running list-packages and choosing which packages to install, while loading happens every time you start Emacs.

The information you added to your init file was setting up your desired package sources, so that you could install packages from the source you prefer, telling the package system to load any installed packages by calling package-initialize, followed by configuring the specific package you are interested in. These were all necessary, but you missed the important step of actually installing that package :).

db48x
  • 15,741
  • 1
  • 19
  • 23
  • Thank you. It says that the archive is melpa so I think that the add-to-list line should do that, right ? Atleast it says that at the link here in the answer by elethan. In fact, this is where I got the code in the first place. Your help is still appreciated. https://emacs.stackexchange.com/questions/18982/how-do-i-make-auto-complete-enabled-by-default – mark leeds Oct 21 '21 at 06:03
  • What was left out of that answer was that at some point you have to actually install the package. Installing the package downloads it from the internet, unpacks it, and puts it where Emacs can find it. Unless you actually do that, your Emacs will not be able to use the package. – db48x Oct 21 '21 at 06:33
  • Thanks. That's a huge piece of wisdom. I'll check out how to do that. There's probably some "beginners emacs-ess manual or document for EXTREME dummies" somewhere but I haven't found it yet. Thanks again. – mark leeds Oct 21 '21 at 06:46
  • I don't want to change my original question but I added the two lines ( at the end of this ) after the package-initialize statement. I then ran eval-buffer in a scratch buffer and it said: "Cannot open load file, no such file or directory, "auto-complete". (add-to-list 'load-path "~/.emacs.d/lisp/") (load "auto-complete") – mark leeds Oct 21 '21 at 07:15
  • Note that I'm not clear on the difference between loading and installing so it's possible that I'm still not installing it. thanks. – mark leeds Oct 21 '21 at 07:16
  • 1
    Modifying your init file won’t help. You should open emacs, ignore the error you’re currently getting, run the command `list-packages` interactively (that is, type `M-x` then type `list-packages` and hit enter). This will download a list of packages from MEPLA, since that is your package source. Find `auto-complete` in this list of packages. Move your cursor down to that line and type `i` to mark it for installation. Feel free to mark any other packages you want as well. Finally, type `x` to execute these instructions. Emacs will download and install the marked packages. – db48x Oct 21 '21 at 07:35
  • "Installing" as @db48x says, is done once: you tell emacs to install a package from MELPA which grabs the lisp files of the package (and other stuff possibly) from some remote system and copies them to your local system. Once a package is installed, it is available for "loading" just as any other files that are built-in to emacs. "Loading" is generally done every time you start emacs, which is why you do it in your init file. So after you install the package using the instructions in the previous comment, `package-initialize` will do the loading for you. – NickD Oct 21 '21 at 13:41
  • IOW, "loading" a package makes the functionality of the package (all the functions and variables defined in the package) available to the running emacs instance. – NickD Oct 21 '21 at 14:09
  • OP or others: If any of the info in the comment trail is important to the question or answers, please consider adding it to the question. Remember: comments can be deleted at any time, and they're not searchable. They're not the place for info that's important to the Q&A. Thx. – Drew Oct 21 '21 at 16:45
  • 1
    Yea, if @markleeds responds and says that this cleared up the problem, I’ll edit the answer to include it all. I don’t see much to indicate that it wouldn’t, though. – db48x Oct 21 '21 at 17:23
  • Thanks to everyone who commented. I use ubuntu and I was using a very outdated version so I'm upgrading to ubuntu 20.04 now to see if that helps. This should give me much closer to current versions of emacs and ess. Then, once that is done, I'll read through all of the wisdom carefully and try whatever people said to do. This is an amazing list with generous and really knowledgable people. All of the help is really appreciated. If the upgrading doesn't finish tonight, then I'll definitely do it over the weekend because tomorrow during the day is not good. – mark leeds Oct 22 '21 at 03:28
  • 2
    This is in regard to db48x's suggestion to take out the two added lines, list the packages and install them using I. IT WORKED LIKE A CHARM !!! No errors when I did emacs --debug-init. So, I'm good now. Thanks to all but particularly db48x and NickD. It's really appreciated. I'm hopefully over the basic-intro hump and can progress in my emacs customization. The positive part of this was that I would have never figured out the whole melpa, list packages and installing thing on my own so asking was definitely necessary. Hopefully I can give this list a break for a good while. Thank you again. – mark leeds Oct 23 '21 at 06:17
  • You’re welcome! – db48x Oct 23 '21 at 12:30
  • One thing you should do is [accept the answer](https://emacs.stackexchange.com/help/someone-answers) (assuming that it did indeed answer your question, as it seems it did). – NickD Oct 31 '21 at 03:42