;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;; ;; .emacs --- EMACS setup file for Linux!!! ;; ;; Update : 08/2023 (Jean-Yves Peterschmitt, Olivier Marti - LSCE) ;; ;; JYP's notes: https://wiki.lsce.ipsl.fr/pmip3/doku.php/other:emacs_doc ;; Official manual: https://www.gnu.org/software/emacs/manual/html_node/emacs/ ;; Emacs wiki: https://www.emacswiki.org/emacs/SiteMap ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Microsoft Windows specific section ;; ;; Search path where emacs should look for the 'unix-like' DiffUtils ;; binaries on Windows required for the ediff mode ;; ;; DiffUtils page: https://gnuwin32.sourceforge.net/packages/diffutils.htm ;; ;; More details on setting the 'path' below: ;; http://www.emacswiki.org/emacs/ExecPath ;; Check with: ;; (getenv "PATH") ;; (executable-find "diff") (when (eq window-system 'w32) (setq exec-path (append exec-path '("C:\\Program Files (x86)\\GnuWin32\\bin"))) ) ;; Do NOT display the Welcome/Info buffer when opening emacs without ;; specifying a file name (setq inhibit-startup-message t ) ;; Remove the tool bar ;; ;; Who clicks on icons anyway? And we want to promote using keyboard ;; shortcuts (tool-bar-mode -1) ;; Turn on automatic syntax highlighting for all buffers (global-font-lock-mode t) ;; Disable ESC-ESC default 'Evaluate Lisp Expression' behavior ;; ;; Use C-x C-e to evaluate an expression, or another method detailed ;; on the link below ;; ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Eval.html (put 'eval-expression 'disabled nil) ;;; Windows/frames' titles ;; ;; More details: https://www.emacswiki.org/emacs/FrameTitle ;; https://www.emacswiki.org/emacs/PercentConstruct ;; ;; (setq frame-title-format "Emacs: %f (%m) %*%+" ) (setq frame-title-format "Emacs: %f" ) ;; Display line and column numbers ;; (setq line-number-mode t) ; Line numbers are now displayed by default (setq column-number-mode t) ;; Lines numbers' start at 1, and we want the column numbers to also ;; start at 1... (setq column-number-indicator-zero-based nil) ;; Sets up time and date in the status line (setq display-time-day-and-date t) (display-time) ;;; Highlight a region (in which cases??) ; Seems to be done by default, now ; (transient-mark-mode t) ;; Do we still need that ? (put 'narrow-to-region 'disabled nil) ;; Do we still need that ? (put 'downcase-region 'disabled nil) ;; Default editing mode when creating/opening a file, when emacs can't ;; guess the file type (from the fime name extension, ...) (setq-default major-mode 'indented-text-mode) ;; Display recent files in the File menu ;; https://www.emacswiki.org/emacs/RecentFiles (require 'recentf) ;; ;; Disable the cleanup feature, because we will (probably) use Tramp ;; Mode to work with remote files! ;; https://www.emacswiki.org/emacs/RecentFiles#h5o-12 (setq recentf-auto-cleanup 'never) ;; disable BEFORE we start recentf! ;; (recentf-mode t) (setq recentf-max-menu-items 25) (setq recentf-max-saved-items 25) (run-at-time nil (* 10 60) 'recentf-save-list) ;; Save every 10 minutes ;; "Dired, the Directory Editor" options ;; ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html ;; ;; Only use ONE Dired buffer (the latest) when navigating directories ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired-Visiting.html (setq dired-kill-when-opening-new-dired-buffer 1) ;; Set up things so that [mouse-1] opens a directory or a file in the ;; same buffer (i.e. replace the Dired buffer with the selected file ;; or the content of the new directory), and [mouse-2] opens the file or ;; new Dired buffer in another buffer (add-hook 'dired-mode-hook (lambda () (local-set-key [mouse-1] 'dired-find-file) (setq-local mouse-1-click-follows-link nil) )) ;;; Full buffer menus (setq complex-buffers-menu-p t) ;; No limitation of the number of buffers displayed in the menu "Buffers" (setq buffers-menu-max-size nil) ;; Try to add and document ferret support later ? ;; (add-to-list 'load-path "~/.emacs-dir" ) ;; (require 'ferret) ;; Define several useful keyboard shortcuts ! ;; ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-Rebinding.html ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Function-Keys.html ;; ;; Moving around (keymap-global-set "S-" 'end-of-line) ; Shift + RIGHT_arrow (keymap-global-set "S-" 'beginning-of-line) ; Shift + LEFT_arrow (keymap-global-set "S-" 'end-of-buffer) ; Shift + DOWN_arrow (keymap-global-set "S-" 'beginning-of-buffer) ; Shift + UP_arrow (keymap-global-set "C-x C-g" 'goto-line) ;; ;; Define what the function keys do (keymap-global-set "" 'undo) (keymap-global-set "" 'query-replace-regexp) (keymap-global-set "" 'fill-paragraph) (keymap-global-set "" 'indent-region) ;; Comment or uncomment each line in the region ;; EXCEPT uncomment does not seem to work (keymap-global-set "" 'comment-region) ;; It is kind of the same as "M-;" ("comment command you want (Do What ;; I Mean)"), except that "M-;" can successfully be used for ;; un-commenting ;; ;; Note: F11 is mapped by default to toggle-frame-fullscreen (keymap-global-set "" 'repeat-complex-command) ;; The old "JYP" color settings (still listed and commented further ;; down) have been replaced by a pre-defined theme, specified in the ;; 'Custom' section at the bottom of this configuration file: ;; wheatgrass -- High-contrast green/blue/brown faces on a black ;; background ;; ;; If you want to try/choose other pre-defined themes: ;; A) Options => Customize Emacs => Custom Themes ;; B) Try the different themes ;; C) If you want to keep the last selected theme (for the next time ;; you start Emacs), click on the "Save Theme Settings" button at the ;; top of the "Custom Themes" buffer. This will add something like ;; '(custom-enabled-themes '(wheatgrass)) ;; in the custom-set-variables at the bottom of the .emacs file ;; ;; ;; The old "JYP" color settings ;; ;; Override the default color of the interface ;; (add-to-list 'default-frame-alist '(background-color . "dark slate gray")) ;; (add-to-list 'default-frame-alist '(mouse-color . "turquoise")) ;; (add-to-list 'default-frame-alist '(cursor-color . "red")) ;; (add-to-list 'default-frame-alist '(foreground-color . "LightGray")) ;; We will use "tramp" to work with REMOTE TEXT FILES ;; Manual: https://www.gnu.org/software/tramp/ ;; ;; Check the 'Custom "Servers" menus' section of this configuration ;; file to see actual examples ;; ;; Tramp uses a special syntax for opening remote files with "C-x C-f" ;; https://www.gnu.org/software/tramp/#File-name-syntax ;; ;; There are several available methods that tramp can use for ;; connecting to remote servers (aka "Inline methods") ;; https://www.gnu.org/software/tramp/#Inline-methods ;; ;; Note: we recommend 'plinkx' for Windows+PuTTY/plink+pass-phrase users ;; https://the.earth.li/~sgtatham/putty/0.78/htmldoc/Chapter7.html#plink ;; ;; Tramp can access files on servers accessible only through a gateway, ;; by using "multiple hops"! ;; https://www.gnu.org/software/tramp/#Multi_002dhops ;; ;; PROBLEM: when using multiple hops to access a remote file, ;; e.g. C-x C-f /ssh:bird@bastion|ssh:you@remotehost:/path RET ;; tramp will only save the final file in the Open Recent menu, ;; e.g. you@remotehost:/path ;; ;; SOLUTION: the following option will automatically save at the end ;; of the ".emacs" (in the custom-set-variables section) the fact that ;; you have to use "/ssh:bird@bastion" before accessing ;; "ssh:you@remotehost:/path" ;; https://www.gnu.org/software/tramp/#Ad_002dhoc-multi_002dhops (customize-set-variable 'tramp-save-ad-hoc-proxies t) ;; Custom "Servers" menus ;; ;; We first define the functions that will call "Dired" that will call ;; "tramp" to access directories on the remote servers, and then we ;; define a menu associating menu (sub-)items with the functions ;; ;; For each server, we define a function using "plinkx" PuTTY/Pageant ;; to connect to the server on Windows machine, and a more general ;; function using "sshx" and ssh that should work on any computer ;; ;; More details about emacs+tramp are available in: ;; https://wiki.lsce.ipsl.fr/pmip3/doku.php/other:emacs_doc#working_with_remote_text_files (defun find-me-at-ssh1-p () (interactive) (message "ssh1 (PuTTY)" ) (dired "/plinkx:me_ssh1:~" ) ) (defun find-me-at-ssh1 () (interactive) (message "ssh1" ) (dired "/sshx:jypeter@ssh1.lsce.ipsl.fr:~" ) ) (defun find-me-at-spirit1-p () (interactive) (message "spirit1 (PuTTY)" ) (dired "/plinkx:me_spirit1:~" ) ) (defun find-me-at-spirit1 () (interactive) (message "spirit1" ) (dired "/sshx:jypmce@spirit1.ipsl.fr:~" ) ) (defun find-me-at-spiritx1-p () (interactive) (message "spiritx1 (PuTTY)" ) (dired "/plinkx:me_spiritx1:~" ) ) (defun find-me-at-spiritx1 () (interactive) (message "spiritx1" ) (dired "/sshx:jypmce@spiritx1.ipsl.fr:~" ) ) (defun find-me-at-irene-p () (interactive) (message "irene (PuTTY)" ) (dired "/plinkx:me_ssh1|ssh:p25jype@irene.ccc.cea.fr:~" ) ) (defun find-me-at-irene () (interactive) (message "irene)" ) (dired "/sshx:jypeter@ssh1.lsce.ipsl.fr|ssh:p25jype@irene.ccc.cea.fr:~" ) ) ;; ;; Actually create the "Servers" menu by using easy-menu-define to ;; associate menu items with functions ;; ;; More details about easy-menu-define are available below (easy-menu-define servers-menu global-map "A menu to easily work will files on remote servers" '("Servers" ("LSCE" ["ssh1 (PuTTY)" find-me-at-ssh1-p t] ["ssh1" find-me-at-ssh1 t] ) ("Spirit[x]" ["spirit1 (PuTTY)" find-me-at-spirit1-p t] ["spirit1" find-me-at-spirit1 t] ["spiritx1 (PuTTY)" find-me-at-spiritx1-p t] ["spiritx1" find-me-at-spiritx1 t] ) ("TGCC" ["irene (PuTTY)" find-me-at-irene-p t] ["irene" find-me-at-irene t] ) ) ) ;; ;; Try to use easy-menu to add a new servers' menu to the menu bar ;; ;; ;; ;; The following menu creation test is based on the examples available in ;; ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Easy-Menu.html ;; ;; and https://www.emacswiki.org/emacs/EasyMenu ;; ;; ;; ;; General menu creation documentation (in case we need a deeper ;; ;; understanding of how easy-menu-define works) ;; ;; ;; ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Menus.html ;; ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Extended-Menu-Items.html ;; ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Menu-Items.html ;; ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Keymaps.html ;; ;; (easy-menu-define my-new-menu global-map "My Servers' menu (or some documentation)" ;; ;; ;; '("Servers 2" ;; ["One entry (Forward word)" forward-word t] ;; ("Some Sub Menu Name" ;; ["My sub-entry (Forward word)" forward-word t] ;; ["Backward word" backward-word t]) ;; ("LSCE" ;; ["ssh1 (PuTTY)" find-me-at-ssh1 t]) ;; ) ;; ) ;;; ;;; Run emacs server ;;; Disabled for now. Need to experiment with this, especially on MS Win ;;; ;; (cond (window-system (server-start))) (require 'server) ;; (setq server-socket-dir "~/.emacs.d/server") ;; https://stackoverflow.com/questions/885793/emacs-error-when-calling-server-start (when (and (>= emacs-major-version 23) (equal window-system 'w32)) ;; Suppress error "directory ~/.emacs.d/server is unsafe" on Windows. (defun server-ensure-safe-dir (dir) "Noop" t)) (if (not (server-running-p)) (server-start)) (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. '(default ((t (:family "Cascadia Code" :foundry "outline" :slant normal :weight normal :height 98 :width normal))))) (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. '(custom-enabled-themes '(wheatgrass)) '(tramp-default-proxies-alist '(("^irene\\.ccc\\.cea\\.fr$" "^p25jype$" #("/plinkx:me_ssh1:" 0 16 (tramp-ad-hoc t))))))