.emacs-defs
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 16 Jun 2021 12:50:08 +0300
changeset 1734 ae2c6a001464
parent 1717 3c60aeba5004
permissions -rw-r--r--
Add some standard places to PATH if they are not set by login script. Rearrange the order of paths so system's are first, user's are last. For Cygwin this helps with Cygwin's paths to be situated before "C:/Windows" (Emacs is not started from a login shell on Windows!).

;; -*- mode: emacs-lisp; coding: utf-8; fill-column: 78; no-byte-compile: t; -*-

(defvar my-profiler-enabled nil
  "Switch for enabling startup profiling.

Put value to '~/.emacs.d/.emacs-pre' which isn't overridden on installation.")

(defvar my-lisp-usr-home-dir
  (expand-file-name "~/usr/share/emacs/site-lisp")
  "There is a place for additional lisp packages installed via 'DIST=~/usr make install'.")

(defvar my-lisp-dir
  (expand-file-name (concat user-emacs-directory "mylisp/"))
  "Here live my lisp packages.")
(add-to-list 'load-path my-lisp-dir)

(defvar my-org-dir "~/my/gtd"
  "Root directory for my Org files.")

(defvar my-lisp-autoload (concat my-lisp-dir "loaddefs.el")
  "Path to autoload for mode files.")
(defvar my-lisp-auth (concat user-emacs-directory ".emacs-auth")
  "Path to auth info for Emacs.")
(defvar my-lisp-autogen (concat user-emacs-directory ".emacs-autogen")
  "Path to automatically generated config file. It content depend on
  installation environment and it was overridden on install.")
(defvar my-lisp-pre (concat user-emacs-directory ".emacs-pre")
  "Path to file with pre-settings. Intended for local modifications.")
(defvar my-lisp-dotemacs (concat user-emacs-directory ".emacs-my")
  "Path to file with settings. Overwritten on install.")
(defvar my-lisp-post (concat user-emacs-directory ".emacs-post")
  "Path to file with post-settings. Intended for local modifications.")

(setq custom-file (concat user-emacs-directory ".emacs-custom"))
(setq save-place-file (concat user-emacs-directory ".emacs-places"))
(setq bookmark-default-file (concat user-emacs-directory "bookmarks"))
(setq ido-save-directory-list-file (concat user-emacs-directory ".ido.last"))

(setq
 package-archives
 '(("gnu" . "https://elpa.gnu.org/packages/")
   ("melpa-stbl" . "https://stable.melpa.org/packages/")
   ("melpa" . "https://melpa.org/packages/"))
 package-archive-priorities
 '(("gnu" . 10)
   ("melpa-stbl" . 5)
   ("melpa" . 0)) )

(setq
 package-selected-packages
 '(adoc-mode
   apache-mode
   dockerfile-mode
   groovy-mode
   markdown-mode
   terraform-mode
   web-mode
   yaml-mode
   expand-region
   helm
   ))

(defun my-lisp--install-external-packages ()
  ;; (package-initialize)
  ;; Update `package-archive-contents'.
  (advice-add #'y-or-n-p :override (lambda (prompt) t))
  (package-refresh-contents)
  ;; (package-install 'yaml-mode)
  (package-install-selected-packages))

(defun my-lisp--load-pre ()
  (mapc (lambda (f)
          (when (file-exists-p f)
            (load f nil nil t)))
        (list custom-file my-lisp-autogen my-lisp-auth my-lisp-pre my-lisp-autoload)))

(defun my-lisp--load-usr-home ()
  "Add hierarchy `my-lisp-usr-home-dir' to `load-path'."
  (when (file-directory-p my-lisp-usr-home-dir)
    (add-to-list 'load-path my-lisp-usr-home-dir)
    (let ((default-directory my-lisp-usr-home-dir))
      (normal-top-level-add-subdirs-to-load-path))))

(defun my-lisp--load-all ()
  "Load everything to help during byte compilation to spot errors
better. Not for regular use but for the Makefile."
  (my-lisp--load-usr-home)
  (my-lisp--load-pre))

(defmacro my--eval-after-load (feature &rest forms)
  (declare (indent defun))
  `(,(if (or (not (boundp 'byte-compile-current-file))
             (not byte-compile-current-file)
             (if (symbolp feature)
                 (require feature nil :no-error)
               (load feature :no-message :no-error)))
         'progn
       (message "my--eval-after-load: cannot find %s" feature)
       'with-no-warnings)
    (eval-after-load ',feature
      '(funcall (lambda () ,@forms)))))