3

Suppose I want Emacs to be configured differently depending on whether or not it was launched with a filename as an argument. Is there a way I can deduce this as part of my init file?

One way is to check if there are any buffers open:

(require 'cl-lib)

(defun non-user-buffer (buffer)
  (let ((name (buffer-name buffer)))
    (when (or (string-prefix-p " " name)
              (and (string-prefix-p "*" name) (string-suffix-p "*" name)))
        t)))

(defun num-user-buffers ()
  (length (cl-remove-if 'non-user-buffer (buffer-list))))

;; Provided recently launched...
(defun launched-with-buffer ()
  (when (> (num-user-buffers) 0) t))
Caterpillar
  • 274
  • 1
  • 8

1 Answers1

4

You have access from Emacs Lisp to information about the command line, such as its arguments (variable command-line-args).

See the Elisp manual, node Command Line Arguments.

Drew
  • 75,699
  • 9
  • 109
  • 225