Samuele Palazzi

"The more i see, the less i know"

Samuele Palazzi

"The more i see, the less i know"

How to configure Emacs


Emacs configuration for beginners and experts users too

This guide is for who would like to configure Emacs in the best way; This method will take clean your directory, clean files in which any lines is commented and let you backup and restore as-is entirely Gnu emacs for future settings.
This step are described for GNU/linux's users but you will be able to use them in a similar way for Windows too and in a very similar way on mac os

Let's start

emacs directory
Emacs directory: this is the only directory we will use

Emacs's configuration's file

Gnu Emacs has two way to initial configuration:

Create a directory to store your lisp file

To configure emacs in the best way, create a subdirectory into ~/.emacs.d directory to store your lisp files, in this example i called lele_lispdir (just because "lele" is the name of linux user).

To configure Emacs in the best way, copy this line into your init.el files

(require 'package)
;; add MELPA repository 
(add-to-list 'package-archives
'("MELPA Stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
;; email settings data 
(load "~/.emacs.d/lele_lispdir/000_email_settings.el")
;; add personal data
(load "~/.emacs.d/lele_lispdir/001_personal_data.el")
;; tell emacs in which directory find themes to customize emacs
(load "~/.emacs.d/lele_lispdir/002_add_theme_dir.el")
;; add window settings
(load "~/.emacs.d/lele_lispdir/003_menu_border_scrollbars.el")
;; add org-mode basilar settings
(load "~/.emacs.d/lele_lispdir/004_org-mode-custom-settings.el")
;; add the file with all the hooks of installed packages
(load "~/.emacs.d/lele_lispdir/005_allTheHooks.el")
This files that we load on emacs startup are separated per content type and in the following step we setup every single file!
The Numeration used as prefix are just to order them from 0 to 999.

add-to-list 'package-archives ...

this is just to setup a repository in which we will can find some packages to configure emacs

000_email_settings.el

;; Se usate MailMode
(setq send-mail-function 'smtpmail-send-it)

;; Indica il server SMTP
(setq smtpmail-default-smtp-server "smtp.server.com")
(setq smtpmail-local-domain "smtp.server.com")
(setq smtpmail-sendto-domain "smtp.server.com")
     (setq smtpmail-smtp-server "smtp.server.com")

;; Indica le credenziali di accesso al server SMTP
(setq smtpmail-auth-credentials '(("smtp.server.com" 465 "myfullname@server.com" "password")))

;; Avvia la libreria smtpmail
(load-library "smtpmail")

;; Al posto di nil potete mettere altre opzioni come parens, angles o system-default
(setq user-mail-address "myfullname@server.com"
      user-full-name "My full name"
      mail-from-style 'nil)

(setq mail-user-agent 'sendmail-user-agent)

001_personale_data.el

;; just before you have to create the directory "backups" inside ~/.emacs.d
;;set firefox as default browser
(setenv "BROWSER" "firefox")
;;set mail data for pdf generated by Emacs in org-mode
(setq user-full-name "My full name"
      user-mail-address "myfullname@server.com"
      ;;calendar-latitude 00.00
      ;;calendar-longitude 00.00
      ;;calendar-location-name "City (RP) - State"
      )
(setq make-backup-files nil) ; stop creating backup~ files
(setq auto-save-default nil) ; stop creating #autosave# files
;; backup in one place. flat, no tree structure
(setq backup-directory-alist '(("" . "~/.emacs.d/backups")))

002_add_theme_dir.el

;; just before you have to create the directory "themes" inside ~/.emacs.d
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")

003_menu_border_scrollbars.el

(tool-bar-mode 0)
(menu-bar-mode 0)
(fringe-mode '(12 . 0))
(when window-system (scroll-bar-mode -1))
;better math simbols
(global-prettify-symbols-mode t)
;ring bell
(setq ring-bell-function 'ignore)
(setq scroll-conservatively 100)
;better js indentation
(setq js-indent-level 2)

004_add_theme_dir.el

(add-hook 'org-mode-hook
(lambda ()
(org-bullets-mode t)))
(setq org-hide-leading-stars t)
(add-hook 'org-mode-hook #'org-bullets-mode)
(setq org-ellipsis "⤵")
 (org-babel-do-load-languages
  'org-babel-load-languages
  '(
    ;(emacs-lisp . nil) we do not need cause it is deja set as default
    (sh . t)
    )
  )

005_allTheHooks.el

When you configure Emacs you may need packages from melpa repository, so you can install them and then you can setup hooks for this packages. As a php programmer i've setup those packages and configured relative hooks in the file "005_allTheHooks.el". Packages installad for PHP programming:

;;Treemacs
(global-set-key (kbd "M-p") 'ace-window) ;ace-window can switch selected window
;;IEdit
(define-key global-map (kbd "C-c ;") 'iedit-mode)
;;Web-mode
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html\\.twig\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
;;php-mode
(require 'php-mode)
(eval-after-load 'php-mode
  '(require 'php-ext))
;;Expand region
(require 'expand-region)
(global-set-key (kbd "C-=") 'er/expand-region)
;;Quickrun
(require 'quickrun)
;;Smartparens
(require 'smartparens-config)
(add-hook 'php-mode-hook #'smartparens-mode)
(add-hook 'web-mode-hook #'smartparens-mode)
(require 'timeclock)
(timeclock-mode-line-display)
(define-key global-map (kbd "C-c C-i") 'timeclock-in)
(define-key global-map (kbd "C-c C-o") 'timeclock-out)
;;abolisci C-z to end with emacs
(global-set-key (kbd "C-z") 'ace-window)
(global-set-key (kbd "C-x C-z") 'ace-window)
;;flymake-phpcs-codesniffer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(load "~/.emacs.d/lele_lispdir/flymake-phpcs/flymake-phpcs.el")
;; If flymake_phpcs isn't found correctly, specify the full path
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(setq flymake-phpcs-command "~/.emacs.d/lele_lispdir/flymake-phpcs/bin/flymake_phpcs")
;; Customize the coding standard checked by phpcs
;;(setq flymake-phpcs-standard
;;  "~/projects/devtools/php_codesniffer/MyCompanyStandard")
;; Show the name of sniffs in warnings (eg show
;; "Generic.CodeAnalysis.VariableAnalysis.UnusedVariable" in an unused
;; variable warning)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(setq flymake-phpcs-show-rule t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(require 'flymake-phpcs)
;;now set the flymake-php that we have installed to get activated on php pages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(add-hook 'php-mode-hook #'flymake-php-load)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(add-hook 'php-mode-hook #'auto-complete-mode)
(setq inhibit-startup-screen t)
(setq initial-scratch-message "This is the Not common home for emacs: just a scratch page in which you can set everything you need")

Restart emacs

After restart Emacs it will start with all configured files and loading all the hooks; In future the only thing you will need to do is to backup the ~/.emacs.d directory and just paste it in the home directory of the new system.

It will works!

Emacs markdown mode
Emacs MarkDown mode