Skip to content

Latest commit

 

History

History
1272 lines (964 loc) · 32 KB

emacs.org

File metadata and controls

1272 lines (964 loc) · 32 KB

An Emacs Literate Configuration

Emacs Configuration

./emacs.org.jpg

This is an org file which generates my personal emacs configuration, this configuration is tailored to my taste and needs.

General notes and hints

Hints

Execute any code block with C-c C-c, adding :tangle no will prevent to add this code to the generated configuration.

Notes

About using use-package:

Refer to the official documentation:

When using :commands, it creates an autoload for those commands and defers loading the module until they are actually used, bear in mind when setting the key-bindins in :init (executed before loading the package), that needs to succeed either way.

The code below is just an example of using :commands and :init configurations, this code will be not appended to the configuration file, kept for learning purposes only.

:defer t will lazy-load the package when is used, this is enabled when other fields of use-package like :hook, setting :defer nil will load the package immediatly.

Prologue

;; generated from emacs.org file

Performance related improvement:

  • Make gc pauses faster by decreasing the threshold.
  • The default is 800 kilobytes, measured in bytes.
;; gc for faster initialization
(setq gc-cons-threshold (* 50 1000 1000))

Global Variables

;; melpa repository
(setq custom/v-melpa "https://melpa.org/packages/")

;; foreground, background color
(setq custom/v-color-bg nil)
(setq custom/v-color-fg nil)

;; font family, height
(setq custom/v-font-fam nil)
(setq custom/v-font-ht nil)

;; is linux
(setq custom/v-is-linux nil)

;; is darwin
(setq custom/v-is-darwin nil)

;; linux or darwin
(cond
 
 ((eq system-type 'gnu/linux)
  (setq custom/v-color-bg '(background-color . "#1c2023"))
  (setq custom/v-color-fg '(foreground-color . "#c7ccd1"))
  (setq custom/v-font-fam "Monospace")
  (setq custom/v-font-ht 100)
  (setq custom/v-is-linux t))

 ((eq system-type 'darwin)
  (setq custom/v-color-bg '(background-color . "#121212"))
  (setq custom/v-color-fg '(foreground-color . "#d8dee8"))
  ;;(setq custom/v-font-fam "Courier New") ;; fh 120
  ;;(setq custom/v-font-fam "Monaco") ;; fh 120
  ;;(setq custom/v-font-fam "Liberation Mono");; fh 120
  (setq custom/v-font-ht 120)
  (setq custom/v-is-darwin t))
 )

Packages

Melpa and package configuration

;; package
(require 'package)
(add-to-list 'package-archives (cons "melpa" custom/v-melpa) t)
(package-initialize)

List of packages used by this configuration.

;; package list
(setq package-selected-packages
      '(
        use-package
        doom-themes
        lsp-mode
        multiple-cursors 
        all-the-icons
        powerline
        neotree
        fill-column-indicator
        bazel
        groovy-mode
        yaml
        yaml-mode
        haskell-mode
        elfeed
        json-mode
        rainbow-delimiters
        which-key
        ivy
        ivy-rich
        counsel
        treemacs
        visual-fill
        visual-fill-column
        dashboard
        org-auto-tangle
        evil
        undo-fu
        evil-collection
        swiper
        smooth-scrolling
        no-littering
        doom-modeline
        nix-haskell-mode
        projectile
        magit
        rust-mode
        yasnippet
        lsp-treemacs
        flycheck
        company
        avy
        helm-xref
        dap-mode
        ))

;; auto install
(when (cl-find-if-not #'package-installed-p package-selected-packages)
  (package-refresh-contents)
  (mapc #'package-install package-selected-packages))

Enable the use-package package, useful when configuring and lazy loading packages.

;; use-package
(require 'use-package-ensure)
(setq use-package-always-ensure t)

Look and feel

Theme and frame configuration

General setting, frame independent:

(display-time)
(savehist-mode 1)

;; no startup screen, no bell
(setq inhibit-startup-screen t)
(setq ring-bell-function 'ignore)

Function to defined the look and feel of the editor:

  • It configures scroll bars, line nums, etc.
  • Append to the frame-parameters the custom fore and background colors each time a new frame is open, this is useful when emacsclient is being used instead of running a standanlone emacs process.
;; look
(defun custom/f-config-look ()
  (interactive)
  (save-excursion)

  ;; theme
  (use-package doom-themes :defer nil)

  ;; doom-one
  ;;(load-theme 'doom-one t)

  ;; atom-one-dark
  ;;(load-theme 'atom-one-dark t)

  ;; doom-nord
  (load-theme 'doom-nord t)
  (setq doom-nord-brighter-comments nil)

  ;; general settings
  (menu-bar-mode -1)      ;; no bar
  (tool-bar-mode -1)      ;; no tool bar
  (scroll-bar-mode -1)    ;; no scroll bar
                                        ;(set-fringe-mode 10)    ;; fringe to 10
  (column-number-mode 1)  ;; column number in the mode line
  (line-number-mode 1)    ;; line number in the mode line
  (global-linum-mode 0)   ;; line number in the buffer left margin
  (global-hl-line-mode 0) ;; line highlight

  (setq vc-follow-symlinks t)  ;; follow symlinks, default 'ask'

  ;; enable parenthesis hightlight
  (show-paren-mode 1)
  (setq show-paren-delay 0)

  ;; reset text scale
  (text-scale-set 0)

  ;; tabs
  (setq-default indent-tabs-mode nil)
  (setq-default c-basic-offset 4)
  (setq-default py-indent-offset 4)
  (setq standard-indent 4)
  (setq c-default-style "linux" c-basic-offset 4)
  (setq scroll-step 1)
  (setq make-backup-files nil)
  (setq auto-fill-mode 1)
  (setq next-line-add-newlines nil)

  ;; paren
  (show-paren-mode 1)
  (setq show-paren-delay 0)

  ;; frame parameters

  ;; initial-frame-alist
  (add-to-list 'initial-frame-alist custom/v-color-bg)
  (add-to-list 'initial-frame-alist custom/v-color-fg)
  (add-to-list 'initial-frame-alist '(width . 180))
  (add-to-list 'initial-frame-alist '(height . 65))
  ;;(add-to-list 'initial-frame-alist '(fullscreen . maximized))

  ;; default-frame-alist
  (add-to-list 'default-frame-alist custom/v-color-bg)
  (add-to-list 'default-frame-alist custom/v-color-fg)
  (add-to-list 'initial-frame-alist '(width . 180))
  (add-to-list 'initial-frame-alist '(height . 65))
  ;;(add-to-list 'default-frame-alist '(fullscreen . maximized))

  ;; font
  (set-face-attribute 'default nil
                      :family custom/v-font-fam
                      :height custom/v-font-ht)

  ;; line spacing
  (setq-default line-spacing 0.1))

If is in daemon mode, hook the frame to reload the look and feel settings, otherwise, the emacsclient and every new frame in it will not load the color and other settings.

(if (daemonp)
    (add-hook 'after-make-frame-functions
              (lambda (frame)
                (with-selected-frame frame (custom/f-config-look))))
  (custom/f-config-look))

Fold/Unfold

Fold

(defun custom/f-fold ()
  (interactive)
  (save-excursion
    (end-of-line)
    (hs-toggle-hidding)))
(global-set-key (kbd "C-c C--") 'custom/f-fold)

Unfold

(defun custom/f-ufold ()
  (interactive)
  (save-excursion
    ;;(move-beginning-of-line)
    (hs-show-block)))
(global-set-key (kbd "C-c C-=") 'custom/f-ufold)

Scrolling

Smooth scrolling, from https://www.emacswiki.org/emacs/SmoothScrolling:

scroll one line at a time (less “jumpy” than defaults)

  • (setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
  • (setq mouse-wheel-progressive-speed nil) ;; don’t accelerate scrolling
  • (setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
  • (setq scroll-step 1) ;; keyboard scroll one line at a time
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) 
(setq mouse-wheel-progressive-speed nil)
(setq mouse-wheel-follow-mouse 't)
(setq scroll-step 1)

Previous block is disabled from tangle, there’s a package to deal with this, enable it only for linux since my emacs on MacOS already support smooth scrolling.

(if custom/v-is-linux
    (use-package smooth-scrolling
	 :defer nil
	 :config
	 (smooth-scrolling-mode)))

Powerline

Powerline documentation at https://github.com/jonathanchu/emacs-powerline.

(use-package powerline
  :defer nil
  :config
  ;;(powerline-nano-theme)
  (powerline-default-theme)
  ;;(setq powerline-image-apple-rgb t)
  (setq powerline-arrow-shape 'arrow))

Change the modeline settings:

(custom-set-faces
 '(mode-line
   ((t (:foreground "#000" :background "#c0c0c0" :box nil))))
 '(mode-line-inactive
   ((t (:foreground "#f9f9f9" :background "#666666" :box nil)))))

Doom Modeline documentation at https://github.com/seagle0128/doom-modeline.

(use-package doom-modeline
  :init (doom-modeline-mode 1)
  :custom ((doom-modeline-height 24)
	     (doom-modeline-icon nil)))

All the Icons

Install the fonts: M-x all-the-icons-install-fonts

(use-package all-the-icons
  :if (display-graphic-p))

Behavior

Bindings

Bindings to move around the buffers, global keysets and def alises.

;; global set keys

(global-set-key "\C-l" 'goto-line)

(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
;;(global-set-key (kbd "C-x C-b") 'ibuffer)

(global-unset-key (kbd "C-z"))

(fset 'yes-or-no-p 'y-or-n-p)

Aliases

;; aliases
(defalias 'select-all 'mark-whole-buffer)

Org

;; orgmode

C- ' can be used to edit source code block, same keybinding can be used to enter and exit the mini editor (which supports syntax highlighting).

C-c C-c can execute the code within the source code block.

The setup is structured in two functions, one that does the general configuration and the other that is intended to be executed by the hook.

Among other things, what basically does is:

  • Disable auto-identation (after titles)
  • Break the line an 80, alt + q will autobreak the line
  • Visually hide the begin_src statements:
  • Remove emphasis markers
  • Structured templates, expanded with <el + tab
(defun custom/f-org-config ()
  ;; remove emphasis markers
  (setq org-hide-emphasis-markers t)

  ;; don't ask y/n when exec babel code
  (setq org-confirm-babel-evaluate nil)

  ;; disable auto-identation
  (setq org-indent-mode -1)
  (setq org-adapt-indentation nil)

  ;; source code blocks identation (left padding)
  (setq org-edit-src-content-indentation 2)
  (setq org-src-preserve-indentation nil)

  ;; babel configuration
  (org-babel-do-load-languages
   'org-babel-load-languages '((emacs-lisp . t)
                               (python . t)))

  ;; org-tempo, structured templates, "<el + tab" to expand template
  (require 'org-tempo)

  (add-to-list 'org-structure-template-alist
               '("sh" . "src shell"))

  (add-to-list 'org-structure-template-alist
               '("el" . "src emacs-lisp"))

  (add-to-list 'org-structure-template-alist
               '("py" . "src python"))

  (add-to-list 'org-structure-template-alist
               '("nn" . "src text :tangle no")))

(defun custom/f-org-hook ()
  ;; look
  (fci-mode 0)
  (linum-mode 0)

  ;; content padding
  (visual-fill-column-mode)

  ;; display inline images
  (org-display-inline-images)

  ;; break column at 80
  (setq fill-column 80)
  (auto-fill-mode)

  ;; prettify symbols
  (setq-default prettify-symbols-alist
                '(("#+begin_src" . "")
                  ("#+begin_src emacs-lisp" . "")
                  ("#+begin_src text :tangle no" . "")
                  ("#+end_src" . "")))
  (setq prettify-symbols-unprettify-at-point 'right-edge)
  (prettify-symbols-mode))

(defun custom/f-org-face-block()
  (interactive)
  (save-excursion)
  (custom-set-faces
   '(org-block-begin-line
     ((t (
          ;;:underline "#A7A6AA"
          ;;:foreground "#008ED1"
          :background "#1e1e1e"
          :extend t))))
   '(org-block
     ((t (
          :background "#1e1e1e"
          :extend t))))
   '(org-block-end-line
     ((t (
          ;;:overline "#A7A6AA"
          ;;:foreground "#008ED1"
          :background "#1e1e1e"
          :extend t))))
   ))

(use-package org
  :defer t
  :config
  (custom/f-org-config)
  (custom/f-org-face-block)
  :hook (org-mode . custom/f-org-hook))

Padding org-mode content to center or not, limited up to 80 chars:

(use-package visual-fill-column
  :defer t
  :hook
  (lambda ()
    ((setq visual-fill-column-width 80)
     (setq visual-fill-column-center-text nil)
     (visual-fill-column-mode 1))))

Tangle configuration:

  • use :tangle no in each block to avoid include the source code block in the

final file generated.

Auto-Tangle:

(use-package org-auto-tangle
  :defer t
  :after org
  :hook (org-mode . org-auto-tangle-mode))

Supporting more lang modes, e.g.: adding conf-unix:

;; (push '("conf-unix" . conf-unix) org-src-lang-modes)

Term

Key bindings to take in count:

  • C-c o, emulates C-x o
  • C-c C-j, term-line-mode
  • C-c C-k, go back to char mode
  • C-c C-c, emulates a ctrl+c sent to the terminal
(use-package term
  :defer t
  :init
  (setq-default shell-file-name "/bin/bash") ;; doesn't work with term
  :commands term
  :config
  (fci-mode 0)
  (linum-mode 0)
  (hl-line-mode 0))
(defun termc ()
  (interactive)
  (save-excursion)
  (term "/bin/bash"))

Dashboard

(use-package dashboard
  :config
  (dashboard-setup-startup-hook)
  (setq dashboard-projects-backend 'projectile)
  (setq dashboard-startup-banner
        (concat (file-name-directory (file-truename user-init-file))
                "emacs.dashboard.33.png"))
  (setq dashboard-banner-logo-title "")
  (setq dashboard-items '((recents  . 5)
                          (bookmarks . 5)
                          (projects . 5)
                          (agenda . 5)
                          (registers . 5))))

;;(with-current-buffer "*scratch*" (goto-char (point-max))
;;(insert (format "\ndd = %s" buffer-file-name)))

Packages

These are the packages that can be configured by itself, other packages like powerline, visual-fill-column are configured where are needed.

Fill Column Indicator

It draws a line at char 79, 0 to 79.

(use-package fill-column-indicator
  :defer t
  :config
  (setq fci-rule-column 79)
  (setq fci-rule-width 1)
  (setq fci-rule-color "grey22"))

Whitespace

Set the face to red from (including) char 80.

(use-package whitespace
  :defer t
  :custom
  (setq whitespace-line-column 80)
  :config
  (setq whitespace-style '(face lines-tail)))

Rainbow delimiters

(use-package rainbow-delimiters
  :hook
  (prog-mode . rainbow-delimiters-mode))

Multiple Cursors

(use-package multiple-cursors
  :defer t
  :commands (mc/edit-lines mc/mark-next-word-like-this)
  :init
  (global-set-key (kbd "C-c m c") 'mc/edit-lines)
  (global-set-key (kbd "C->") 'mc/mark-next-word-like-this))

This is the code that actually be apended to the configuration file, it will autoload the package when it is actually used, that means the key-binding is section is evaluated.

(use-package multiple-cursors
  :defer t
  :bind (("C-c m c" . 'mc/edit-lines)
         ("C->" . 'mc/mark-next-word-like-this)))

Treemacs

;; on the treemacs buffer
;; C-c p is the prefix command.
(use-package treemacs
  :defer t
  :config
  (progn (setq treemacs-no-png-images t))
  (treemacs-resize-icons 14)
  (dolist (face '(treemacs-root-face
		    treemacs-git-unmodified-face
		    treemacs-git-modified-face
		    treemacs-git-renamed-face
		    treemacs-git-ignored-face
		    treemacs-git-untracked-face
		    treemacs-git-added-face
		    treemacs-git-conflict-face
		    treemacs-directory-face
		    treemacs-directory-collapsed-face
		    treemacs-file-face
		    treemacs-tags-face))
    (set-face-attribute face nil :family custom/v-font-fam :height custom/v-font-ht)))

No Littering

Keep emacs folder and project folders clean, :defer is set to nil:

(use-package no-littering
  :defer nil
  :init
  (setq user-emacs-directory "~/.cache/emacs")
  :config
  (setq auto-save-file-name-transforms
	  `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))

Evil Mode

Check the undo-fu package for vim style undo, disabled for now.

(use-package undo-fu
  :defer t)

(use-package evil
  :demand t
  :bind (("<escape>" . keyboard-escape-quit))
  :init
  (setq evil-want-keybinding nil)
  (setq evil-undo-system 'undo-fu)
  :config
  (evil-mode 1))

(use-package evil-collection
  :after evil
  :config
  (setq evil-want-integration t)
  (evil-collection-init))

Elfeed

This is a feed reader within emacs:

(use-package elfeed
  :defer t
  :config
  (setq elfeed-feeds
        (quote
         (("https://news.ycombinator.com/rss" tech hackernews)
          ("https://blog.tartanllama.xyz/feed.xml" programming cpp)
          ("https://linuxnewbieguide.org/feed/" tech linux)))))

It is possible to change the default browser, e.g.:

(setq browse-url-browser-function 'eww-browse-url)

Ivy

  • Alt only to complete and not to open a file, exec a command, etc, refer to abo-abo/swiper#86.
  • For enable/disable ^ for counsel-M-x, refer to /questions/38841/counsel-m-x-always-shows.

This configuration does a partial search, means that execute the seleccion on <ret> and not with double-tab.

;; ivy
(use-package ivy
  :diminish
  :bind (("C-s" . swiper)
	   :map ivy-minibuffer-map
	   ("C-l" . ivy-alt-done)
	   ("C-j" . ivy-next-line)
	   ("C-k" . ivy-previous-line)
	   ("<tab>" . ivy-partial) ;; partial search
	   ("<ret>" . ivy-alt-done) ;; done with <ret>
	   :map ivy-switch-buffer-map
	   ("C-k" . ivy-previous-line)
	   ("C-l" . ivy-done)
	   ("C-d" . ivy-switch-buffer-kill)
	   :map ivy-reverse-i-search-map
	   ("C-k" . ivy-previous-line)
	   ("C-d" . ivy-reverse-i-search-kill))
  :config
  (ivy-mode 1))

Ivy Rich

(use-package ivy-rich
  :defer nil
  :after ivy
  :init
  (ivy-rich-mode 1))

Counsel

(use-package counsel
  :bind (("M-x" . counsel-M-x)
	   ("C-x C-b" . counsel-ibuffer)
	   ("C-x C-f" . counsel-find-file)
	   :map minibuffer-local-map
	   ("C-e" . 'counsel-minubuffer-history))
  :config
  ;; will avoid start search with ^
  ;; (setq ivy-initial-inputs-alist nil) 
  (fci-mode 0))

What about these?

  • (setq ivy-use-virtual-buffers t)
  • (setq enable-recursive-minibuffers t)

Which Key

This is triggered by C-h {v,f}, v stands for variable, f for functions, etc.

(use-package which-key
  :init (which-key-mode)
  :diminish which-key-mode
  :config
  (setq which-key-idle-delay 1))

Projectile

Key binding is set to C-c p, there’s a bunch of comands to run.

(use-package projectile
  :diminish projectile-mode
  :config (projectile-mode)
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :init
  (when (file-directory-p "~/projects/")
    (setq projectile-project-search-path '("~/projects/")))
  (setq projectile-switch-project-action #'projectile-dired))

Magit

(use-package magit
  :defer t
  :config
  (global-set-key (kbd "C-x g") 'magit-status))

IDEs

Rust

Rust - Mode

Documentation, refert to https://github.com/rust-lang/rust-mode

Use C-c C-c to execute cargo run.

For some reason (which I don’t know really) it won’t let me to add the indent and enable lsp in the use-package :hook section, that’s why it is the way is coded.

(use-package rust-mode
  :bind (:map rust-mode-map
              ("C-c C-c" . rust-run))
  :config
  (add-hook 'rust-mode-hook #'lsp)
  :hook
  (custom/f-config-look)
  )

Rust - Language Server Protocol

Documentation, refer to https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-rls/

Server setup:

rustup update
rustup component add rls rust-analysis rust-src

There’s a hook that enable lsp in rust-mode.

Daemon

Server

To start emacs daemon within emacs, closeing that emacs session running the daemon, will kill the server as well.

(server-start)

As a daemon from the command line:

# as a daemon
emacs --daemon

# as a foreground daemon, debugging purposes
emacs --fg-daemon

# a name daemon if necessary
emacs --daemon[={daemon name}]

Check emacs daemon running, list /tmp/emacs1000 and list the socket files.

Kill the server and client running against that server too.

emacsclient -e "(kill-server)" [-s {name}]
emacsclient -e "server-socker-dir"
emacsclient -e "(counsel-switch-buffer)"

There’s a systemd support for emacs in most linux distros:

sudo systemctl --user enable emacs
sudo systemctl --user start emacs

Client

# launch emacs client
# -c, with a new name
# -n, don't wait, -a for a
# -a, alternative editor
# -u, supress output
# -s, socket name or daemon name
# -mm, maximize
emacsclient -c -n -a emacs

# use it as an editor, e.g.: git commit
export EDITOR="emacsclient -c -a emacs"

In MacOS, emacsclient is in:

  • /Applications/Emacs.app/Contents/MacOS/bin-x86_64-10_11/emacsclient

It is recommended to create an alias or a function so when a new frame is open form the command line without specifying any file, it opens the dashboard, e.g.:

emacsclient -c -e '(switch-to-buffer "*dashboard*")'

Configuration

This is an example on how to check if is running in daemon mode or not, if is a “named” dameon, it will return the name of the daemon.

(if (daemonp)
    (message "emacs, daemon mode")
  (message "emacs, standalone mode"))

Custom Functions

;; (treemacs-add-project-to-workspace PATH &optional NAME)
;; (projectile-add-known-project PROJECT-ROOT)

(defun choose-directory (directory)
  "sample that uses interactive to get a directory"
  (interactive (list (read-directory-name "What directory? " 
                                          choose-directory-default-directory)))
  (message "You chose %s." directory))

(defvar choose-directory-default-directory "~"
  "Initial starting point.")

This function (below) sets the current working directory

;; set treemacs to --cwd argument

(require 'treemacs-macros)
(require 'treemacs-customization)
(require 'treemacs-logging)
(require 'treemacs-themes)
(require 'treemacs-icons)
(require 'treemacs-faces)
(require 'treemacs-visuals)
(require 'treemacs-rendering)
(require 'treemacs-core-utils)
(require 'treemacs-scope)
(require 'treemacs-follow-mode)
(require 'treemacs-filewatch-mode)
(require 'treemacs-mode)
(require 'treemacs-interface)
(require 'treemacs-persistence)
(require 'treemacs-async)
(require 'treemacs-compatibility)
(require 'treemacs-workspaces)
(require 'treemacs-fringe-indicator)
(require 'treemacs-header-line)
(require 'treemacs-annotations)

(defun custom/treemacs-select-directory (directory)
  (interactive)
  (setq default-directory directory)
  (message default-directory)

  (treemacs-block
   (let* ((path (expand-file-name default-directory))
          (name (treemacs--filename path))
          (ws (treemacs-current-workspace)))

     (treemacs-return-if
         (and (= 1 (length (treemacs-workspace->projects ws)))
              (string= path (-> ws
                                (treemacs-workspace->projects)
                                (car)
                                (treemacs-project->path))))
       (treemacs-select-window))
     (treemacs--show-single-project path name)
     (treemacs-pulse-on-success "Now showing %s"
       (propertize path 'face 'font-lock-string-face))))


  ;; get dired buffer name from path
  (setq dired-buffer-name
        (file-name-nondirectory
         (directory-file-name
          (file-name-directory directory))))
  (message dired-buffer-name)

  ;; kill dired buffer
  (kill-matching-buffers dired-buffer-name)
  (delete-other-windows)

  ;; swith to the scratch buffer
  (switch-to-buffer "*scratch*")

  ;; dashboard-mode, dashboard-refresh-buffer
  )

;; so 13672229
;;(setq default-directory (or x (getenv "PWD")))
(add-to-list
 'command-switch-alist
 '("--cwd" . (lambda(x)
               (custom/treemacs-select-directory
                (car command-line-args-left)))))

Epilogue

Available faces, print them out in the current buffer:

;; it appends to the current buffer each face name
(mapc (lambda (face)(insert (format "\n%s" face))) (face-list))

Disable face’s bold for everything but org faces. I came up with this code block it has a lot of room for improvements, like e.g.: don’t format face as a string, and test the match in other way (by not having a match.group(1) nil to disable what is intended).

This, needs to be improved, orgmode filter doesn’t work, it seems it also disable another face used by orgmode.

;; set bold off EVERYWHERE but orgmode
;;(set-face-bold-p 'bold nil) ;; disable bold fonts

(defun custom/f-is-org-face (face)
  (setq matchstr nil)
  (setq facestr (format "%s" face))
  (save-match-data
    (and (string-match "^.*\\(org\\).*$" facestr)
         (setq matchstr (match-string 1 facestr))))
  (if (null matchstr)
      (set-face-attribute face nil :weight 'normal :underline nil)
    ;; (with-current-buffer "*scratch*"
    ;;   (goto-char (point-max))
    ;;   (insert (format "\n%s" facestr)))
    ))

(mapc (lambda (face)(custom/f-is-org-face face)) (face-list))

Line Highlighting, Line Number, FCI Mode, etc:

Emacs modes inherits from super modes or base modes, e.g.:

  • lisp-mode inherits from prog-mode.
  • prog-mode inherits from fundamental-mode
  • text-mode inherits from fundamental-mode.

Lets enable the hl and other line modes on prog modes, org-mode and text-mode, there’s no way to enable globally and disabled it per major mode.

;; enable fci, linenum, hl and whitespace for prog
;; modes only

(defun custom/prog-mode-hooks ()
  (fci-mode 1)
  (linum-mode 1)
  (hl-line-mode 1)
  (whitespace-mode 1)
  (hs-minor-mode 1)
  (mapc (lambda (face)(custom/f-is-org-face face)) (face-list)))

(add-hook 'prog-mode-hook 'custom/prog-mode-hooks)
(add-hook 'text-mode-hook (lambda () (hl-line-mode 1)))
(add-hook 'org-mode-hook (lambda () (hl-line-mode 1)))

Configure garbage collector frequency:

(setq gc-cons-threshold (* 2 1000 1000))
;; eof
;; below this line, there's pure garbage

Emacs Notes

  • company, company “just” does code/text autocompletion and a few related things like docstring lookup
  • ivy, ivy is a framework for interactively picking something out of a lists in a nicer way (here using ivy as a better M-x)
  • swiper, swiper is another application of ivy, using ivy as a better C-s

Configuration todo:

  • [ ] company
  • [ ] evilmode
  • [ ] plantuml
  • [ ] pdf
  • [ ] command-log-mode
  • [ ] autosave
  • [ ] async package
  • [ ] dsp, gdb
  • [ ] rust, gdb
  • [ ] faces counsel

Find out:

  • [ ] (autoload ‘ace-jump-mode “ace-jump-mode” nil t) + use-package
  • [ ] defun vs progn
  • [ ] avoid #+results when installing packages
  • [ ] eval-after-load v/s hooks /2736087/eval-after-load-vs-mode-hook
  • [ ] emacs/lisp alist
  • [ ] defcustom, e.g.: rust-cargo.el
  • [ ] #, ‘, #’, x . y
  • [ ] Magit + Rebase
  • [ ] setq-default

Useful keybindings and commands:

general,  M-;        toggle code comments
general,  M-x M-p    to traverse M-x history (with ivy-counsel)
command,  M-x        describe-personal-keybindings    
treemacs, C-c C-p    a to add, d to delete, etc.

Review packages:

Sources

These are links that helped me to tweak my emacs configuration. There’s a lot of emacs and lisp documentation.