emacs init.el from scratch

To get familiar with emacs you really need to customise it to make it usable. I'm currently checking out various guides related to init.el and would be interested in any advice/comments on how to organise it.

These pages gave me plenty to think about:-


 
It's slow going getting something together initially, but a couple of important things for me is having a horizontally split screen and an easy to flip between them, as well as enabling org-mode.
Since buffer management is important in getting the most out of emacs, a couple of buffer management commands are included.


Code:
;;;;Org mode configuration
(require 'org)
;; Make Org mode work with files ending in .org  

(split-window-horizontally)
(find-file "~/to-do.org")    ;; load initial file

(global-set-key (kbd "<f12>") 'other-window) ;; toggle between left and right windows

;; change default  from open buffer list to open list of buffers in same window to enable selection
(global-set-key "\C-x\C-b" 'buffer-menu)

(global-set-key (kbd "C-<prior>") 'previous-buffer) ; page up key
(global-set-key (kbd "C-<next>") 'next-buffer) ; page up key

(global-set-key (kbd "<f3>") 'kill-current-buffer)
 
To get familiar with emacs you really need to customise it to make it usable. I'm currently checking out various guides related to init.el and would be interested in any advice/comments on how to organise it.
You could try looking at this repo as a way to modularise your emacs configuration. Each module is given a numeric prefix to enable the files to be loaded in a specific order, and the code to load the files in the correct order is in init.el.
 
One of the things which made a major difference for me in using emacs, which I do in text mode (emacs -nw) was:-

Code:
set term=xterm-256color

in /etc/csh.cshrc which suddenly enabled me to have usable colours.
 
Two modes which I'm trying to get to grips with at the moment at dired and org mode.

I've been reading quite a bit a about dired+, and have copied it to ~/.emacs.d, but haven't managed to load it.
Whilst in dired mode I've that C-h m gives you all the commands and key bindings available in dired. Not yet sure if it is possible to get the help file opened in the other window rather in the window showing the directory listing. Also found the very useful '^' for going up a directory level. It was frustrating trying to do that before I learnt this command.

In org mode I can't yet master creating a link to a web page.

Shows how but I can't get this working.

If/when I do I would like to use www/lynx to open the link if possible.
 
One important part of emacs is package management. To enable installation of packages you need to enter the following into init.el.

Code:
(require 'package)                                                                                                                                                             
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)                                                                                                   
                                                                                                                                                                              
                                                                                                                                                                              
(package-initialize)                                                                                                                                                           
                                                                                                                                                                              
(package-install 'use-package)                                                                                                                                                 
                                                                                                                                                                              
(require 'use-package)                                                                                                                                                         
                                                                                                                                                                              
                                                                                                                                                                              
(use-package command-log-mode)

use-package info
 
In org mode I can't yet master creating a link to a web page.
In your .org file type C-c C-l (that's l for 'link'). Org should prompt you for the URL that you want to embed in the page and once you've entered that and hit return it will prompt you for the description of the link i.e. the text that gets displayed on the page. You can take a look at this page in the Org manual for more info.
 
Try running M-x load-file ~/.emacs.d/dired+.el
One thing I'm uncertain about with lisp files is when do you need to provide a full path for loading. There are options like default-directory and load-path which I think I need to set. I see in my freshly installed emacs 29.1 in a 13.2 jail has default-directory set to /etc. Not sure why this should be as I didn't set it.
 
Actually, you should avoid adding 3rd party files to your ~/.emacs.d directory. This directory is really meant to store configuration files only, not lisp packages. Instead create a new directory under ~/.emacs.d (named 'lisp' or 'elisp' or 'custom' or 'packages' or something similar), place any emacs lisp files there, and then add that new directory to your emacs load path using the following command in your config file:

(add-to-list 'load-path "~/.emacs.d/<new-directory>")
 
I've never used the dired+ package. However, the fact that the package is not part of any of the standard Emacs package repositories is a bit of a red flag. My advice to you would be to stick with the standard packages (almost 10K of them) until you have a good grasp of the basics. To use FreeBSD as an analogy, it's like expecting a novice user to run CURRENT instead of RELEASE. They're going to come across lots of issues and struggle to fix them. It's not a problem, we've all been there, but it's best to take small steps and learn stuff from the ground up. Less haste more speed etc.

Here's a simplistic learning path that you can follow to get more experience:

1. If you haven't already, complete the tutorial that comes with Emacs (C-h t)
2. Open the in-built manual in Emacs, split your screen vertically (C-x 3) and work through it from front to back while experimenting.
3. Learn enough Emacs Lisp to be able to read other people's config files by loading the Emacs Lisp Intro manual, splitting the screen again and copying the examples into the *scratch* buffer, running them as you read.
4. Change any setting to see what it does. If it doesn't get written to your config file it will reset back to the previous value the next time you (re)load Emacs.

It's a long journey but best to start with the basics and build on them. Hope this helps.
 
I was only interested in dired+ because I had read about it offering a lot more than standard dired. I'm interested in trying to use emacs as a file manager as a replacement for midnight commander and it's taking some doing. Dired mode has so many options and its a slow process working out what they all do.

I always open emacs with C-x 3 and am trying to figure out how to copy/move files between two dired panels. Need to figure out which dired functions are involved.
 
I always open emacs with C-x 3 and am trying to figure out how to copy/move files between two dired panels. Need to figure out which dired functions are involved.
I don't use dired much, however, the following looks like it will do what you want:

Put (setq dired-dwim-target t) in your init file and either reload the file or restart Emacs. Then, in dired, split your window vertically with the two directories that you want to work with on either side. Then when you press C to copy, the directory in the other pane should be the default destination.
 
Since a new version of emacs (29.1) has just been released, it's worth seeing what's new...


Not sure how much of it will work on FreeBSD.
 
One key bindings I find myself using most is:-

Code:
(global-set-key (kbd "<f9>") 'shell-command-on-region)

This allows me to mark some text for an eventual shell script and the press F9 and sh() and test it out.

This can also be used with sed() and probably man other commands.

The output can be seen in the *Shell Command Output* buffer.
 
Back
Top