0

When I switch on my computer, 1st things I do: Open GNU Emacs, C-x C-f [file name A], Enter, C-x C-f [file name B], Enter, C-x b, Enter - in doing so going back to buffer of file A - C-x s, es - searching for a certain spot in file A - C-c C-o - opening a link in the web browser

That happens every day without an exeption! Day by day, can't that be automated some how to save time & effort?

How? I have some ideas, but finally am too unexperienced in making it work - I also can't program, yet. I assume a kbd macro of said steps could be placed into that so called init file. But this vague idea isn't enough, and still one open question is how to make GNU Emacs start automatically every time I switch on or restart the computer.

The file /GNU Emacs/ is appreciated as being in a buffer every session. I would keep that. It's just that I want a different file as being a landing page or '1st thing displayed after starting my GNU Emacs'.

I am using GNU Emacs 24.5.1 on a fully free/libre GNU/Linux distribution - free as in freedom.

Issue halfway solved: Automatic start of GNU Emacs right after booting & restarting of the computer works! And it's really easy to achieve: Probably at least most GNU/Linux OS have a desktop task bar with menu button. Clicking on this and navigating through the menu options one can get to a place like 'System > Preferences > Personal > Startup Applications'. This path leads to an options window where there are already some programs set as startup applications, and all what has to be done from there is clicking on the 'add' button and adding GNU Emacs to that list this way.

So, all what still needs to be solved now is: 'How to make those couple of first actions right after start of GNU Emacs automatically?' I still think that best grab would be to somehow make any of those spots with init files also contain a kbd macro, which gets triggered as 1st action after the general GNU Emacs startup. But how does that work? I've looked into the manual and GNU Emacs regarding init files and got very confused and frustrated: There is not just 1 spot for the init file, there are a couple of spots for or with init files! And I don't have a clue what spot to prefer for editing an init file for what reason and how many init files are necessary on my system, anyway. And when you look at videos or elsewhere around, anybody says something else, uses a different spot for making an init file or init file edit. I just can't tell: What way is appropriate or the best in my case. And I don't know, if it's possible, at all, to edit the init structure in a way that it ends startup with executing a kbd macro.

Update: We're up to something thanks to alephnull! The plan: Adding a function to emacs-startup-hook, which executes the couple of steps I do by hand whenever I start an emacs session.

The thing is this: I've tried to put this hint into action, but it has no effect on how emacs starts - as if I haven't changed anything at /.emacs .

Here's what I have done:

  1. Making the function, which is supposed to execute the things I do manually whenever an GNU Emacs session starts.

For that I made a kbd macro, and saved it in form of lisp code on my computer, so that I can copy and paste the snippet later.


1.2. Making kbd macro
1.2.1. C-x ( ;; starting kbd macro definition
1.2.2. C-x C-f testfile A ;; find testfile A
1.2.3. C-x ) ;; end kbd macro definition

1.3. Saving kbd macro
1.3.1. C-x C-k n kbd macro 1 ;; naming the kbd macro "kbd macro 1" for saving
1.3.2. M-x insert-kbd-macro ;; still being in testfile A now the following lisp code is in the file:

(fset 'kbd\ macro\ 1
   (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([24 6 116 101 115 116 102 105 108 101 32 65 return] 0 "%d")) arg)))

  1. Editing /.emacs

Before:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(ansi-color-names-vector
   [ *certain values* ])
 '(browse-url-browser-function (quote browse-url-generic))
 '(browse-url-generic-program
   " *path of certain program* ")
 '(custom-enabled-themes (quote ( *certain theme* )))
 '(desktop-save-mode nil))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

After:

I assumed that inserting the hook should be done right after the line with '(desktop-save-mode nil)) in a new line, have the same format as the other lines, and incorporate only the lambda-part.

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(ansi-color-names-vector
   [ *certain values* ])
 '(browse-url-browser-function (quote browse-url-generic))
 '(browse-url-generic-program
   " *path of certain program* ")
 '(custom-enabled-themes (quote ( *certain theme* )))
 '(desktop-save-mode nil)
 '(add-hook 'emacs-startup-hook (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([24 6 116 101 115 116 102 105 108 101 32 65 return] 0 "%d")) arg))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

I've saved /.emacs & testfile A like that. From that point on I expected and hoped, that when I start Emacs, first thing I see will be a buffer containing testfile A. But that didn't happen. Instead I still saw GNU Emacs as the first thing after GNU Emacs start.

How come that said edit has no effect? Actually to my understanding my init file /.emacs should end with doing the sequence of actions stored in the kbd macro. But that doesn't happen puzzled ...

1

You probably want to start with desktop-save-mode.

There are parts to your question which I have not addressed.

  • starting emacs automatically on boot, this is usually OS specific
  • opening recently used files

With desktop-save-mode, unless something bad happens, restarting emacs will bring you back to exactly where you were including registers, tab/window configuration...

3
  • I'm not sure about it: I have 2 problems with it. Problem #1: What I want is rather like a specific desktop checkpoint, which doesn't change, which is always the same, no matter what buffers I open or close on top of it within a session. desktop-save-mode, however, seems to take every change. Problem #2: How do I activate desktop-save-mode specifically - is it /.emacs? And where in that file specifically? – starquake Apr 18 at 20:56
  • 1
    You might want to take a look at superuser.com/questions/681562/… As for #2, yes, you'd add (desktop-save-mode 1) in your .emacs. – alephnull Apr 20 at 2:39
  • Very good hint! Adding a function to the emacs-startup-hook probably will do the trick! It's just, that due to lack of experience in that area I keep messing it up. I will update the starting posting of this thread, in order to explain in detail what I do and what its effect is in trying to put your hint into action. – starquake Apr 23 at 17:09
0

You could create and use a separate desktop file with your desired start-up configuration like this:

;; To prepare the start-up desktop file...
;; 1. Run a separate temporary instance of Emacs, and within that:
;; 2. M-x make-directory RET ~/.emacs.d/start RET
;; 3. M-x desktop-change-dir RET ~/.emacs.d/start RET
;; 4. Visit files, etc -- create the configuration you wish to store
;; 5. M-x desktop-save-in-desktop-dir
;; 6. Quit the temporary instance of Emacs
;; 7. Add the following to your regular init file
(let (desktop-dirname)
  (desktop-read "~/.emacs.d/start")
  (desktop-release-lock))

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.