Skip to content

Latest commit

 

History

History
504 lines (429 loc) · 15.4 KB

configuration.org

File metadata and controls

504 lines (429 loc) · 15.4 KB

Emacs configuration

Introduction

My’ config for org-mode. The following code must be included in your ~/.emacs or ~/.emacs.d/init.el file (replace /path/to/file/):

(package-initialize)
(setq vc-follow-symlinks t)
(org-babel-load-file "/path/to/file/configuration.org")

Only run first time!:

echo "(package-initialize)" > ~/.emacs.d/init.el
echo "(setq vc-follow-symlinks t)" >> ~/.emacs.d/init.el
echo "(org-babel-load-file \"~/Nextcloud/org/config/configuration.org\")" >> ~/.emacs.d/init.el

The command org-babel-load-file creates configuration.el file which is run during startup

Packages

Melpa (repository)

Tutorial: From youtube video python https://www.youtube.com/watch?v=6BlTGPsjGJk and github repo https://github.com/wernerandrew/jedi-starter and use-package homepage https://jwiegley.github.io/use-package/installation/

(require 'package)
(add-to-list
  'package-archives
  '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

use-package

https://github.com/jwiegley/use-package

;; This is only needed once, near the top of the file
(if (not (package-installed-p 'use-package))
 (progn
   (package-refresh-contents)
   (package-install 'use-package)))

(eval-when-compile
  (require 'use-package))   

company

http://company-mode.github.io/ Company is a text completion framework for Emacs.

(use-package company
  :ensure t
  :defer t
  :diminish (company-mode . "")
  :init
  (global-company-mode)
  :config
  (setq company-tooltip-align-annotations t
        company-idle-delay 0.2
        company-minimum-prefix-length 2
        company-require-match nil))

anaconda-mode

https://github.com/proofit404/anaconda-mode https://www.reddit.com/r/emacs/comments/bg0rue/your_opinion_on_best_config_for_python_development/elht7ak/?utm_source=share&utm_medium=ios_app&utm_name=iossmf As you see, I use the default bindings. I switch to virtual environment using M-x pythonic-activate (pythonic is a dependency of anaconda-mode). I jump to definition via M-.. Autocompletion works via C-M-i and you get nice candidate list if you have ivy installed. There is also default binding for help but I don’t use it. I think there is a way to eval region but I don’t use it since I develop Python libraries and do related interactive testing in Jupyter notebook (actually, in emacs-jupyter, but that’s a different story.)

(setq python-shell-interpreter "/bin/python3")
(use-package anaconda-mode
 :ensure t
 :init 
 (add-hook 'python-mode-hook 'anaconda-mode)
 (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
 (add-hook 'python-mode-hook 'display-line-numbers-mode))

 (eval-after-load "company"
  '(add-to-list 'company-backends 'company-anaconda))

magit

Git version control

(use-package magit :bind ("C-x g" . magit-status) :ensure t)

projectile

https://github.com/bbatsov/projectile

(use-package projectile
:ensure t
:init
(projectile-mode +1)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map))

tramp mode

Built-in. Open file with ssh:user@ip/path/file

emacs-lisp

The scratch buffer can evaluate elisp code. The keyboard shortcut is useful for running elisp function, place cursor at end of function/code and press. Source: https://blog.aaronbieber.com/2016/08/07/getting-started-with-emacs-lisp.html

(define-key lisp-interaction-mode-map (kbd "<C-return>") 'eval-last-sexp)

treemacs

https://github.com/Alexander-Miller/treemacs

(use-package treemacs
:ensure t
:defer t
:init
(with-eval-after-load 'winum
  (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
:config
(progn
 (setq treemacs-collapse-dirs                 (if treemacs-python-executable 3 0)
       treemacs-deferred-git-apply-delay      0.5
       treemacs-directory-name-transformer    #'identity
       treemacs-display-in-side-window        t
       treemacs-eldoc-display                 t
       treemacs-file-event-delay              5000
       treemacs-file-follow-delay             0.2
       treemacs-file-name-transformer         #'identity
       treemacs-follow-after-init             t
       treemacs-git-command-pipe              ""
       treemacs-goto-tag-strategy             'refetch-index
       treemacs-indentation                   2
       treemacs-indentation-string            " "
       treemacs-is-never-other-window         nil
       treemacs-max-git-entries               5000
       treemacs-missing-project-action        'ask
       treemacs-no-png-images                 nil
       treemacs-no-delete-other-windows       t
       treemacs-project-follow-cleanup        nil
       treemacs-persist-file                  (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
       treemacs-position                      'left
       treemacs-recenter-distance             0.1
       treemacs-recenter-after-file-follow    nil
       treemacs-recenter-after-tag-follow     nil
       treemacs-recenter-after-project-jump   'always
       treemacs-recenter-after-project-expand 'on-distance
       treemacs-show-cursor                   nil
       treemacs-show-hidden-files             t
       treemacs-silent-filewatch              nil
       treemacs-silent-refresh                nil
       treemacs-sorting                       'alphabetic-asc
       treemacs-space-between-root-nodes      t
       treemacs-tag-follow-cleanup            t
       treemacs-tag-follow-delay              1.5
       treemacs-width                         30)

(treemacs-follow-mode t)
(treemacs-filewatch-mode t)
(treemacs-fringe-indicator-mode t))
:bind
(:map global-map
     ("M-0"       . treemacs-select-window)
     ("C-x t 1"   . treemacs-delete-other-windows)
     ("C-x t t"   . treemacs)
     ("C-x t B"   . treemacs-bookmark)
     ("C-x t C-t" . treemacs-find-file)
     ("C-x t M-t" . treemacs-find-tag)))

(use-package treemacs-projectile
:after treemacs projectile
:ensure t)

(use-package treemacs-icons-dired
:after treemacs dired
:ensure t
:config (treemacs-icons-dired-mode))

(use-package treemacs-magit
:after treemacs magit
:ensure t)

Orgmode

Initial settings and paths

Getting started, keyboard shortcuts from the manual Source: https://orgmode.org/guide/Activation.html#Activation

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-cb" 'org-switchb)

Variables:

(setq org-directory "~/Nextcloud/org")
(setq org-agenda-files (file-expand-wildcards "~/Nextcloud/org/*.org"))
(setq org-refile-targets '((nil :maxlevel . 9) (org-agenda-files :maxlevel . 9)))

Capture templates

  (setq org-capture-templates
     '(("c" "Inbox"           entry (file+headline "~/Nextcloud/org/gtd.org" "inbox") "* %?\n")
	("x" "Inbox Clipboard" entry (file+headline "~/Nextcloud/org/gtd.org" "inbox") "* %? %x\n")
	("z" "Inbox Clip url"  entry (file+headline "~/Nextcloud/org/gtd.org" "inbox") "* [[%x][%?]]\n")
	("a" "Shopping"     entry (file+headline "~/Nextcloud/org/gtd.org" "inbox") "* BUY %?\n")
				      ))

Agenda templates

  (setq org-agenda-custom-commands
     '(
	("z" "Agenda and next actions"
	 ((agenda "")
	  (todo "NEXT")
	  (todo "BUY")
	 ) nil ("~/Nextcloud/org/agenda.pdf" "~/Nextcloud/org/agenda.html")
	)

       ("x" "Next 60 days of non-repeating events" agenda ""
        ((org-agenda-span 45)                          ;; [1]
         (org-agenda-start-on-weekday 0)               ;; [2]
         (org-agenda-time-grid nil)                    
         (org-agenda-repeating-timestamp-show-all t)   ;; [3]
         (org-agenda-entry-types '(:timestamp :sexp)))  ;; [4]               
	 )
	 ))

Found from https://lists.gnu.org/archive/html/emacs-orgmode/2012-07/msg00409.html Do not show empty days in agenda.

(setq org-agenda-show-all-dates nil)

Orgmode hidden gems

https://yiufung.net/post/org-mode-hidden-gems-pt1/

(setq org-catch-invisible-edits 'show-and-error)

Turn on auto-revert buffer. In case org-files are left open, while using beorg on phone

(global-auto-revert-mode 1)

Based on https://christiantietze.de/posts/2019/03/sync-emacs-org-files/ Auto-save org buffers

(add-hook 'auto-save-hook 'org-save-all-org-buffers)

org-refile settings, hierarchical

http://doc.norang.ca/org-mode.html Also read org.el file in /usr/share/emacs/26.3/lisp/org

(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps nil)
(setq org-refile-allow-creating-parent-nodes 'confirm)
(setq org-refile-targets ( quote (("gtd.org" :maxlevel . 9))))

(ido-mode 1)

Custom functions

Import / export files

The following function is made for making a link-list of files from org-inbox folder and also move to org-files folder Should be run from the end of your inbox item (* inbox)

   (defun mb/org-process-inbox ()
      "Makes list of all files in org-inbox folder, and moves files to org-files"
      (interactive)
      (setq org-inbox-files (directory-files "~/Nextcloud/org/org-inbox/" nil "[^.]"))
      (dolist (cfile org-inbox-files)
	(insert (concat "** [[./org-files/" cfile "][" cfile "]]\n"))
	(rename-file (concat "~/Nextcloud/org/org-inbox/" cfile) "~/Nextcloud/org/org-files/")))

  (global-set-key (kbd "s-<f12>") 'mb/org-process-inbox)

Interface

Mini-buffer auto-complete

(ido-mode 1)

Automatic end parenthesis

(electric-pair-mode 1)

Add undo to ctrl-z

Disabled in favor of cua mode

(global-set-key (kbd "C-z") 'undo)

Add CUA mode

(cua-mode t)

cycle buffer ctrl-tab

(require 'bind-key)
(bind-key* "C-<tab>" 'previous-buffer)
   
;;(global-set-key (kbd "C-<tab>") 'previous-buffer)

switch to gtd buffer

(defun switch-to-gtd ()
  (interactive)
  (switch-to-buffer "gtd.org"))

  (global-set-key (kbd "C-|") 'switch-to-gtd)

Avy goto char timer

(global-set-key (kbd "C-.") 'avy-goto-char-timer)

Theme

(load-theme 'wombat t)

Configs from Brad Wright

Source: https://github.com/bradwright/emacs.d

Line width for word wrapping

(setq-default fill-column 80)

Encoding UTF-8

(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

Switch windows

(global-set-key (kbd "M-o") 'other-window)

Startup

Disable splash startup screen

(setq inhibit-startup-screen t)

Startup size

(add-to-list 'default-frame-alist '(fullscreen . maximized))
;;(setq initial-frame-alist '((top . 1) (left . 1) (width . 135) (height . 95)))
;;(toggle-frame-fullscreen)

Open file on startup

(treemacs)
(find-file "~/Nextcloud/org/gtd.org")
(delete-other-windows)

Resources

These are useful resources for using emacs org-mode and getting configured