3

In my .emacs file I have the following line in custom-set-variables:

 '(initial-buffer-choice "~/Programming/C++/<some project I'm working on>")

This works great. However, I use emacs to edit lots of other files too. Before I inserted the above line in custom-set-variables, I could specify the file I intended to edit from the command line. For example, when I intended to edit a file called text_file.txt, I could type this command:

emacs text_file.txt

And emacs would startup with text_file.txt as the selected buffer. Now that I've specified initial-buffer-choice, regardless of what I say after emacs, emacs will always open the file specified in custom-set-variables, and not the file specified at command line. For example, the command

emacs text_file.txt

now opens ~/Programming/C++/<some project I'm working on> instead of text_file.txt.

How can I over ride initial-buffer-choice so when I do specify which file to open, that file will open?

3
  • Could someone also help me out and add more tags to this question? I don't have enough reputation to create new tags, although some (custom-set-variables and initial-buffer-choice, perhaps) seem fitting to me.
    – user8810
    Jul 4, 2015 at 23:53
  • IMHO, a tag named initial-buffer-choice would be far to specific. You'd probably be the only question with that tag for a very, very long time. Therefore, the tag isn't terribly useful.
    – PythonNut
    Jul 5, 2015 at 0:02
  • @PythonNut I see. I should probably leave it to the meta and more experienced users to define tags.
    – user8810
    Jul 5, 2015 at 0:03

2 Answers 2

1

What happens after Emacs opens to your choice of initial-buffer-choice? If you then use C-x b do you see the file you specified on the command line as an available buffer to choose from? And is it perhaps even the default (try M-n to see if it gets pulled immediately to the minibuffer)?

If yes, then it sounds like Emacs is doing what you told it to:

  1. Visit the file you gave it on the command line.

  2. Show the initial buffer that you chose.

And it's not hard to use C-x b. If the file in question comes up as the default buffer to switch to, things are easier still.

If that is not what you see then this sounds like a bug to me. If you can repro the behavior starting from emacs -Q (with any other specific switches and settings specified as part of the recipe), then consider filing a bug report: M-x report-emacs-bug.

Note too that you can try setting initial-buffer-choice to a function that picks up a command-line file argument and uses that as the buffer to show.

1
  • It turns out the specified files are opened. Like you said, I just have to C-x b to get to them.
    – user8810
    Jul 5, 2015 at 18:19
0

Use a function for that checks if the current buffer has a filename.

(setq initial-buffer-choice
  (lambda ()
    (if (buffer-file-name)
      (current-buffer) ;; leave as-is
      (find-file "~/Programming/C++/<some project I'm working on>"))))

Fo a full example see this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.