资源说明:It is my Emacs configuration, which does not start with a .emacs file anymore... hail to init.el!
#+title: Massimo's Emacs configuration #+author: Massimo Lauria#+STARTUP: collapsed This is the Emacs config of Massimo Lauria (C) 2009-2021. This configuration is under massive and continue change, and things break every day. I just put it online so you can cut & paste whatever you may find useful. This configuration assume a modern Emacs installation (>=24). If your Emacs is less recent than that, the configuration will revert to a minimal version. *Literate configuration*: this Emacs configuration is on the way to be a /literate configuration/ developed as an =org-mode= file. The plan is that the very document you are reading right now will be the main part of the configuration itself. At this point this is not true but I am putting in place the infrastructure for it. I will slowly move part of the main config inside this =README.org= file. * Bootstrapping the setup The variable =base-config-path= keeps the path where the configuration is installed. I add that to the =load-path=, and we also add the path of 3rd parties packages, which are packages I keep in the repository because they are not on =melpa= (yet). #+BEGIN_SRC emacs-lisp (setq 3rdparties-packages-path (concat base-config-path "3rdparties/")) (add-to-list 'load-path base-config-path) (add-to-list 'load-path 3rdparties-packages-path) #+END_SRC The best way to read Info files is in emacs. The client merges all info /dir/ files in a single index. Therefore among other things I make the index to show my local info documents as well. For example my copy of "Structure and Interpretation of Computer Programs". #+BEGIN_SRC emacs-lisp (if (not (boundp 'Info-directory-list)) (setq Info-directory-list nil)) (add-to-list 'Info-directory-list (concat base-config-path "/info")) #+END_SRC ** Adjust =PATH= environment variables When Emacs is lauched as an app (on MacOSX) or from a gui command (in linux) there is often the chance that the running environment does not contain some environment variables or does not set them up appropriately. These functions allow me to care of such issues as long as they arise in my setup. I don't claim any generality here. First I have two functions to manage variables for the runtime environment where Emacs has been executed from. #+BEGIN_SRC emacs-lisp (defun environment-variable-add-to-list (varname element &optional append) "Add ELEMENT from the list in the enviroment variable VARNAME. VARNAME is considered as a list of elements like \"aa:bb:cc\". If VARNAME is undefined of empty, it defines it. If ELEMENT is already in the list, the function won't do anything. There is no guarantee on the actual order of the elements in the list." (let ((separator (if (eq system-type 'windows-nt) ";" ":")) tmplist) (if (getenv varname) (setq tmplist (split-string (getenv varname) separator))) (add-to-list 'tmplist element append 'string-equal) (setenv varname (mapconcat 'identity tmplist ":")))) (defun environment-variable-rm-from-list (varname element) "Remove ELEMENT from the list in the enviroment variable VARNAME. VARNAME is considered as a list of elements like \"aa:bb:cc\". If ELEMENT is not in the list, the function won't do anything. There is no guarantee on the actual order of the elements in the list." (let ((separator (if (eq system-type 'windows-nt) ";" ":")) tmplist) (if (getenv varname) (setq tmplist (split-string (getenv varname) separator))) (setenv varname (mapconcat 'identity (remove element tmplist) ":")))) #+END_SRC I use this functions primarily to fix =PATH=. #+BEGIN_SRC emacs-lisp (defun environment-add-path (newpath &optional append) "Add NEWPATH to the PATH environment variable and to exec-path, Ignore if the path does not exists." (when (file-directory-p newpath) (add-to-list 'exec-path newpath append 'string-equal) (environment-variable-add-to-list "PATH" newpath append))) #+END_SRC Some useful paths to add to the environment. In particular tools like =Cask=, =cabal=, =cargo=, install their executables files in a corresponding hidden folder inside =$HOME=. #+BEGIN_SRC emacs-lisp (environment-add-path "/usr/local/bin") ;; Homebrew (MacOS) (environment-add-path (concat (getenv "HOME") "/.cask/bin")) ;; Cask (for Elisp) (environment-add-path (concat (getenv "HOME") "/.local/bin")) ;; Local/bin (GNU/Linux) #+END_SRC Actually the right way to set system-wide exec-paths on Mac is to use `/etc/paths.d' files. I pick up these paths as well. #+BEGIN_SRC emacs-lisp (with-temp-buffer (condition-case nil (dolist (file (cons "/etc/paths" (directory-files "/etc/paths.d/" t))) (if (not (file-directory-p file)) (insert-file-contents file))) (error nil)) (dolist (path (split-string (buffer-string) "\n" t)) (if (file-directory-p path) (environment-add-path path)))) #+END_SRC ** Private configuration Part of my setup is not for the public eye and is not included in the repository. #+BEGIN_SRC emacs-lisp (let ((private "~/personal/conf/emacs.el")) (when (file-readable-p private) (load-file private))) #+END_SRC * Localization/Internationalization #+BEGIN_SRC emacs-lisp (setenv "LANG" "it_IT.UTF-8") #+END_SRC ** Keyboard Naturally I have my keyboard minor mode. #+BEGIN_SRC emacs-lisp ;; My keyboard configuration (use-package mxl-keyboard :commands (mxl-keyboard-mode mxl-keyboard-global-mode) :diminish "" :config (mxl-keyboard-global-mode) :demand t) #+END_SRC I often type =C-x C-z= by mistake, which hides the current Emacs frame via =susped-frame=. I hate it. #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x C-z") 'nil) #+END_SRC ** Text encoding is always UTF-8 I work mostly with UTF-8 file, Hence UTF-8 is the default coding for buffers. #+BEGIN_SRC emacs-lisp (prefer-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (setq default-buffer-file-coding-system 'utf-8) #+END_SRC The same setting seems to be needed for the clipboard. #+BEGIN_SRC emacs-lisp (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) (set-clipboard-coding-system 'utf-8) #+END_SRC I often need to write greek or math symbols (e.g. α, ⊕), and since I know LaTeX it is convenient to use the same markup to insert them in regular text. Nevertheless it is inconvenient to have that on by default. I activate it when needed typing =C-\= (=toggle-input-method=). #+BEGIN_SRC emacs-lisp (setq default-input-method 'TeX) (set-input-method nil) #+END_SRC ** Italians holidays, timezones and calendar names For me it is useful to have the agenda to remind of italian holidays, especially if they corresponds to vacation days. I override the original values of these variables because I don't care to know about holidays that do not affect me. #+BEGIN_SRC emacs-lisp ;; Non-religious holidays (setq holiday-general-holidays '((holiday-fixed 1 1 "Capodanno") (holiday-fixed 3 8 "Giornata internazionale della donna") (holiday-fixed 5 1 "Festa dei Lavoratori") (holiday-fixed 4 25 "Liberazione dal Nazifascismo") (holiday-fixed 6 2 "Festa della Repubblica"))) ;; Catholics holidays that induce vacations (setq holiday-christian-holidays '((holiday-fixed 12 8 "Immacolata Concezione") (holiday-fixed 12 25 "Natale") (holiday-fixed 12 26 "Santo Stefano") (holiday-fixed 1 6 "Epifania") (holiday-easter-etc -52 "Giovedì grasso") (holiday-easter-etc -47 "Martedì grasso") (holiday-easter-etc 0 "Pasqua") (holiday-easter-etc +1 "Pasquetta") (holiday-fixed 8 15 "Ferragosto") (holiday-fixed 11 1 "Ognissanti"))) ;; No other religious holidays induce vacation days in Italy. (setq holiday-bahai-holidays nil) (setq holiday-hebrew-holidays nil) (setq holiday-islamic-holidays nil) #+END_SRC In Italy the weekly calendar starts from Monday, hence I set =calendar-week-start-day= accordingly. It is also nice to have the names of months and weekdays translated. #+BEGIN_SRC emacs-lisp (setq calendar-week-start-day 1 calendar-day-name-array ["Domenica" "Lunedì" "Martedì" "Mercoledì" "Giovedì" "Venerdì" "Sabato"] calendar-month-name-array ["Gennaio" "Febbraio" "Marzo" "Aprile" "Maggio" "Giugno" "Luglio" "Agosto" "Settembre" "Ottobre" "Novembre" "Dicembre"]) #+END_SRC Several packages (e.g. Org-mode) need to recognize what a weekday name or a month name is. Package =parse-time= provides this functionality, but it only knows about English words. I can add the Italian ones to ~parse-time-weekdays~ and ~parse-time-months~ when package =parse-time= is loaded. I also add the timezones. #+BEGIN_SRC emacs-lisp :tangle no (defconst parse-time-weekdays '(("dom" . 0) ("lun" . 1) ("mar" . 2) ("mer" . 3) ("gio" . 4) ("ven" . 5) ("sab" . 6) ("domenica" . 0) ("lunedì" . 1) ("martedì" . 2) ("mercoledì" . 3) ("giovedì" . 4) ("venerdì" . 5) ("sabato" . 6)) "Italian weekdays to add to `parse-time-weekdays'.") (defconst parse-time-months-ita '(("gen" . 1) ("feb" . 2) ("mar" . 3) ("apr" . 4) ("mag" . 5) ("giu" . 6) ("lug" . 7) ("ago" . 8) ("set" . 9) ("ott" . 10) ("nov" . 11) ("dic" . 12) ("gennaio" . 1) ("febbraio" . 2) ("marzo" . 3) ("aprile" . 4) ("maggio" . 5) ("giugno" . 6) ("luglio" . 7) ("agosto" . 8) ("settembre" . 9) ("ottobre" . 10) ("novembre" . 11) ("dicembre" . 12)) "Italian manths to add to `parse-time-months'.") (use-package parse-time :config (setq parse-time-months (append parse-time-months parse-time-months-ita)) (setq parse-time-weekdays (append parse-time-weekdays parse-time-weekdays-ita)) (add-to-list 'parse-time-zoneinfo '("cet" 3600 t) t) ;; Central European Time (add-to-list 'parse-time-zoneinfo '("cest" 7200) t) ;; Central European Summer Time ) #+END_SRC * Appearance ** Fonts The most important visual setup for a text editor is the font. Several families of fonts are tried in order of preference, and the first which is present in the machine is picked as default font. =symbol-font= is the fallback needed for some math symbols. #+BEGIN_SRC emacs-lisp (cond ((find-font (font-spec :name "Fira Code")) (setq default-font "Fira Code 18")) ((find-font (font-spec :name "DejaVu Sans Mono")) (setq default-font "DejaVu Sans Mono 18")) ((find-font (font-spec :name "Menlo")) ;; Default of macOS (setq default-font "Menlo-18")) ((find-font (font-spec :name "Inconsolata")) (setq default-font "Inconsolata-18")) ;; Default on Windows (t (setq default-font "Monospace-18"))) ;; Last resort (setq symbol-font "DejaVu Sans Mono") #+END_SRC I like Emacs to open in a wide frame at the center of the screen, on startup, at least on these systems with floating window managers. No internal border except for a small fringe on the left side. I disable any other decorations. Text is more readable with some additional space between lines. #+BEGIN_SRC emacs-lisp (setq initial-frame-alist '((top . 0.5) ;; center vertical position (left . 0.5))) ;; center horizontal position (setq default-frame-alist `((font . ,default-font) (height . 64) (width . 120) (tool-bar . nil) (line-spacing . 0.2) (internal-border-width . 0) (border-width . 0) (vertical-scroll-bars . nil) (horizontal-scroll-bars . nil) (left-fringe . 8) (right-fringe . 0) (tool-bar-lines . 0) (menu-bar-line . 0) )) #+END_SRC Some glyphs are not includes in the default font, thus emacs uses a fallback which sometimes is less than desirable. In particular this messes up the alignment in ~helm-bibtex~. For such characters I use an alternative fallback font. *Hint:* To discover the properties of some text on the screen the command ~C-u C-x =~ gives them all: font, style, font-lock, char code. #+BEGIN_SRC emacs-lisp (defun mxl-fix-bibfonts (frame) (set-fontset-font t #x2318 symbol-font) ; ⌘ (set-fontset-font t #x270e symbol-font) ; ✎ (set-fontset-font t nil "Symbola")) ; other fonts like
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。