mirror of https://github.com/Chizi123/.emacs.d.git

Joel Grunbaum
2020-02-24 be9cffb0ef508a4f8d91e66e4dec97180151289a
config.org
@@ -1,7 +1,7 @@
#+TITLE: My Emacs configuration
#  LocalWords:  poppler mingw emacs eq nt gnuplot setenv mapconcat el cond minibuffer pdf color Smartparens smartparens yas aindent whitespace eldoc ielm ibuffer hippie pscp pos Spaceline spaceline powerline spacemacs seperator dir Yasnippet yasnippet flycheck magit fullscreen CEDET askifnotset semanticdb EDE ede gdb srefactor analyzer eval cdb autosetup ghostscript math unicode reftex bibtex TeXcount texcount str latin rkt PlantUML plantuml autoload alist matlab verilog ds vh src fontify natively fortran dvipng plist xcolor EXWM Zenburn setq zenburn defun dolist init config DejaVu ispell aspell flyspell kbd recentf sexp ov bg listp defadvice progn prog keyfreq autosave dabbrev hl gc linum linux utf RET ARG arg configs backends contribs AucTex tex auctex LaTeX url
#  LocalWords:  poppler mingw emacs eq nt gnuplot setenv mapconcat el cond minibuffer pdf color Smartparens smartparens yas aindent whitespace eldoc ielm ibuffer hippie pscp pos Spaceline spaceline powerline spacemacs seperator dir Yasnippet yasnippet flycheck magit fullscreen CEDET askifnotset semanticdb EDE ede gdb srefactor analyzer eval cdb autosetup ghostscript math unicode reftex bibtex TeXcount texcount str latin rkt PlantUML plantuml autoload alist matlab verilog ds vh src fontify natively fortran dvipng plist xcolor EXWM Zenburn setq zenburn defun dolist init config DejaVu ispell aspell flyspell kbd recentf sexp ov bg listp defadvice progn prog keyfreq autosave dabbrev hl gc linum linux utf RET ARG arg configs backends contribs AucTex tex auctex LaTeX url htmlize
* Windows dependencies
* COMMENT Windows dependencies
Dependencies needed for Aspell, poppler PDF-tools, compilers and ghost-script provided by mingw64
#+BEGIN_SRC emacs-lisp
  (when (eq system-type 'windows-nt)
@@ -45,8 +45,9 @@
** Default font
#+BEGIN_SRC emacs-lisp 
  ;;(set-frame-font "DejaVu Sans Mono" nil t)
  ;; (set-frame-font "DejaVu Sans Mono" nil t)
  (set-frame-font "Dank Mono-11" nil t)
  ;; (set-frame-font "Source Code Pro-10" nil t)
  (set-face-italic 'font-lock-comment-face t)
  (set-face-italic 'font-lock-keyword-face t)
#+END_SRC
@@ -105,10 +106,18 @@
** PDF-tools
#+BEGIN_SRC emacs-lisp
(use-package pdf-tools
  :ensure t
  :config
  (pdf-tools-install))
  (use-package pdf-tools
   :ensure t
   :config
   (pdf-tools-install 1))
#+END_SRC
** COMMENT Writegood-mode
Supposedly should provide insight to writing quality
#+BEGIN_SRC emacs-lisp
  (use-package writegood-mode
    :ensure t
    :hook (text-mode . writegood-mode))
#+END_SRC
* Helm and Projectile
@@ -172,6 +181,129 @@
    (helm-projectile-on))
#+END_SRC
** COMMENT ggtags
#+BEGIN_SRC emacs-lisp
    (use-package ggtags
      :ensure t
      :bind (("C-c g s" . ggtags-find-other-symbol)
           ("C-c g h" . ggtags-view-tag-history)
           ("C-c g r" . ggtags-find-reference)
           ("C-c g f" . ggtags-find-file)
           ("C-c g c" . ggtags-create-tags)
           ("C-c g u" . ggtags-update-tags))
      :config
      (add-hook 'c-mode-common-hook
              (lambda ()
                (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
                  (ggtags-mode 1))))
      )
    (setq
     helm-gtags-ignore-case t
     helm-gtags-auto-update t
     helm-gtags-use-input-at-cursor t
     helm-gtags-pulse-at-cursor t
     helm-gtags-prefix-key "\C-c g"
     helm-gtags-suggested-key-mapping t
     )
    (use-package helm-gtags
      :ensure t
      :config
      (add-hook 'dired-mode-hook 'helm-gtags-mode)
      (add-hook 'eshell-mode-hook 'helm-gtags-mode)
      (add-hook 'c-mode-hook 'helm-gtags-mode)
      (add-hook 'c++-mode-hook 'helm-gtags-mode)
      (add-hook 'asm-mode-hook 'helm-gtags-mode)
      (define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
      (define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
      (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
      (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
      (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
      (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))
#+END_SRC
** COMMENT Ctags
#+BEGIN_SRC emacs-lisp
  (defvar ctags-command "ctags -e -R --languages=vhdl")
  (defun ctags ()
    (call-process-shell-command ctags-command nil "*Ctags*"))
  (defun ctags-find-tags-file ()
    "Recursively searches each parent directory for a file named
                TAGS and returns the path to that file or nil if a tags file is
                not found or if the buffer is not visiting a file."
    (progn
      (defun find-tags-file-r (path)
        "Find the tags file from current to the parent directories."
        (let* ((parent-directory (file-name-directory (directory-file-name path)))
               (tags-file-name (concat (file-name-as-directory path) "TAGS")))
          (cond
           ((file-exists-p tags-file-name) (throw 'found tags-file-name))
           ((string= "/TAGS" tags-file-name) nil)
           (t (find-tags-file-r parent-directory)))))
      (if (buffer-file-name)
          (catch 'found
            (find-tags-file-r (file-name-directory buffer-file-name)))
        nil)))
  (defun ctags-set-tags-file ()
    "Uses `ctags-find-tags-file' to find a TAGS file. If found,
                set 'tags-file-name' with its path or set as nil."
    (setq-default tags-file-name (ctags-find-tags-file)))
  (defun ctags-create-tags-table ()
    (interactive)
    (let* ((current-directory default-directory)
           (top-directory (read-directory-name
                           "Top of source tree: " default-directory))
           (file-name (concat (file-name-as-directory top-directory) "TAGS")))
      (cd top-directory)
      (if (not (= 0 (ctags)))
          (message "Error creating %s!" file-name)
        (setq-default tags-file-name file-name)
        (message "Table %s created and configured." tags-file-name))
      (cd current-directory)))
  (defun ctags-update-tags-table ()
    (interactive)
    (let ((current-directory default-directory))
      (if (not tags-file-name)
          (message "Tags table not configured.")
        (cd (file-name-directory tags-file-name))
        (if (not (= 0 (ctags)))
            (message "Error updating %s!" tags-file-name)
          (message "Table %s updated." tags-file-name))
        (cd current-directory))))
  (defun ctags-create-or-update-tags-table ()
    "Create or update a tags table with `ctags-command'."
    (interactive)
    (if (not (ctags-set-tags-file))
        (ctags-create-tags-table)
      (ctags-update-tags-table)))
  (defun ctags-search ()
    "A wrapper for `tags-search' that provide a default input."
    (interactive)
    (let* ((symbol-at-point (symbol-at-point))
           (default (symbol-name symbol-at-point))
           (input (read-from-minibuffer
                   (if (symbol-at-point)
                       (concat "Tags search (default " default "): ")
                     "Tags search (regexp): "))))
      (if (and (symbol-at-point) (string= input ""))
          (tags-search default)
        (if (string= input "")
            (message "You must provide a regexp.")
          (tags-search input)))))
#+END_SRC
* Small tweaks
** Remove startup screen
#+BEGIN_SRC emacs-lisp
@@ -214,7 +346,8 @@
    (which-key-mode))
#+END_SRC
** Go to this file
** Config shortcuts
*** Go to this file
#+BEGIN_SRC emacs-lisp
(defun config-visit ()
  (interactive)
@@ -222,7 +355,7 @@
(global-set-key (kbd "C-c e d") 'config-visit)
#+END_SRC
** Go to init.el
*** Go to init.el
#+BEGIN_SRC emacs-lisp
  (defun init-visit ()
    (interactive)
@@ -230,7 +363,7 @@
  (global-set-key (kbd "C-c e i") 'init-visit)
#+END_SRC
** Reload configuration
*** Reload configuration
#+BEGIN_SRC emacs-lisp
(defun config-reload ()
  "Reloads ~/.emacs.d/config.org at run time"
@@ -392,18 +525,21 @@
** Coding style
#+BEGIN_SRC emacs-lisp
(setq c-default-style "linux")
  (setq c-default-style '((java-mode . "java")
                         (awk-mode . "awk")
                         (other . "k&r")))
#+END_SRC
** Coding system
#+BEGIN_SRC emacs-lisp
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
(setq-default indent-tabs-mode t)
(delete-selection-mode)
(global-set-key (kbd "RET") 'newline-and-indent)
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  (set-language-environment "UTF-8")
  (prefer-coding-system 'utf-8)
  (setq-default indent-tabs-mode t
            tab-width 4)
  (delete-selection-mode)
  (global-set-key (kbd "RET") 'newline-and-indent)
#+END_SRC
** Move to beginning of line ignoring whitespace
@@ -485,14 +621,14 @@
* Programming tweaks
** Yasnippet
#+BEGIN_SRC emacs-lisp
    (use-package yasnippet
      :ensure t
      :diminish yas-minor-mode
      :config
      (use-package yasnippet-snippets
   :ensure t)
      (yas-reload-all)
      (yas-global-mode 1))
  (use-package yasnippet
    :ensure t
    :diminish yas-minor-mode
    :config
    (use-package yasnippet-snippets
      :ensure t)
    (yas-reload-all)
    (yas-global-mode 1))
#+END_SRC
** flycheck
@@ -503,7 +639,7 @@
    :config
    (global-flycheck-mode))
#+END_SRC
*** flycheck-pos-tip
*** flycheck-pos-tipe
#+BEGIN_SRC emacs-lisp
(use-package flycheck-pos-tip
  :ensure t
@@ -694,7 +830,7 @@
    (slime-setup '(slime-fancy slime-company)))
#+END_SRC
*** x86
*** COMMENT x86
**** x86-lookup
#+BEGIN_SRC emacs-lisp
(use-package x86-lookup
@@ -743,47 +879,53 @@
    (add-to-list 'company-backends 'company-bibtex))
#+END_SRC
**** COMMENT TeXcount
**** TeXcount
     Word counts in latex
     #+BEGIN_SRC emacs-lisp
       (defun get-texcount-latest()
         (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_1_1.zip" "~/.texcount/texcount.zip" 1)
         (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
         (add-to-list 'exec-path "~/.texcount/texcount.pl"))
      (defun get-texcount-latest()
       (if (not(file-directory-p "~/.texcount"))
          (make-directory "~/.texcount"))
       (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_1_1.zip" "~/.texcount/texcount.zip" 1)
       (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
       (add-to-list 'exec-path "~/.texcount/texcount.pl"))
       (get-texcount-latest)
      (if (not(file-exists-p "~/.texcount/texcount.pl"))
         (get-texcount-latest))
       (defun texcount ()
         (interactive)
         (let*
             ( (this-file (buffer-file-name))
               (enc-str (symbol-name buffer-file-coding-system))
               (enc-opt
                (cond
                 ((string-match "utf-8" enc-str) "-utf8")
                 ((string-match "latin" enc-str) "-latin1")
                 ("-encoding=guess")
                 ) )
               (word-count
                (with-output-to-string
                  (with-current-buffer standard-output
                    (call-process "texcount" nil t nil "-0" enc-opt this-file)
                    ) ) ) )
           (message word-count)
           ) )
       (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
       (add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))
      (defun texcount ()
       (interactive)
       (let*
          ( (this-file (buffer-file-name))
            (enc-str (symbol-name buffer-file-coding-system))
            (enc-opt
            (cond
             ((string-match "utf-8" enc-str) "-utf8")
             ((string-match "latin" enc-str) "-latin1")
             ("-encoding=guess")
             ) )
            (word-count
            (with-output-to-string
              (with-current-buffer standard-output
               (call-process "texcount" nil t nil "-0" enc-opt this-file)
               ) ) ) )
         (message word-count)
         ) )
      (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
      (add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))
     #+END_SRC
*** PlantUML
#+BEGIN_SRC emacs-lisp
(use-package plantuml-mode
  :ensure t
  :init
  (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar"))
  (use-package plantuml-mode
    :ensure t
    :init
    (cond ((eq system-type 'windows-nt)
           (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar"))
          ((eq system-type 'gnu/linux)
           (setq plantuml-jar-path "/usr/share/java/plantuml/plantuml.jar"))))
#+END_SRC
*** Racket
*** COMMENT Racket
**** Major mode
#+BEGIN_SRC emacs-lisp
  (when (eq system-type 'windows-nt)
@@ -865,6 +1007,33 @@
      (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode)))
#+END_SRC
*** MATLAB
Mode for editing MATLAB m-files.
Have to manually install matlab-mode
#+BEGIN_SRC emacs-lisp
  (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
  (add-to-list
   'auto-mode-alist
   '("\\.m$" . matlab-mode))
  (setq matlab-indent-function t)
  (setq matlab-shell-command "matlab")
  (matlab-cedet-setup)
#+END_SRC
*** MIPS
#+BEGIN_SRC emacs-lisp
  (use-package mips-mode
    :ensure t
    :mode "\\.mips$")
#+END_SRC
*** IPython notebooks
Allow emacs to view and use IPython notebooks
#+BEGIN_SRC emacs-lisp
  (use-package ein
    :ensure t)
#+END_SRC
* Org mode
** Up to date org
#+BEGIN_SRC emacs-lisp
@@ -888,15 +1057,15 @@
** Line wrapping
#+BEGIN_SRC emacs-lisp
  (add-hook 'org-mode-hook
         '(lambda ()
       (visual-line-mode 1)))
            '(lambda ()
               (visual-line-mode 1)))
#+END_SRC
** org-bullets
#+BEGIN_SRC emacs-lisp
(use-package org-bullets
  :ensure t
  :config
  (use-package org-bullets
    :ensure t
    :config
    (add-hook 'org-mode-hook (lambda () (org-bullets-mode))))
#+END_SRC
@@ -929,3 +1098,115 @@
    (plist-put dvipng--plist :use-xcolor t)
    (plist-put dvipng--plist :image-converter '("dvipng -D %D -T tight -o %O %f")))
#+END_SRC
* EMMS
Emacs media manager.
#+BEGIN_SRC emacs-lisp
  (use-package emms-setup
    :ensure emms
    :init
    (add-to-list 'load-path "~/elisp/emms/")
    :config
    (emms-all)
    (emms-default-players)
    (setq emms-source-file-directory "~/Music/"))
#+END_SRC
* Org Blog
** Org static blog config
Boiler plate template code for site.
#+BEGIN_SRC emacs-lisp
  (use-package org-static-blog
    :ensure t
    :config
    (setq org-static-blog-publish-title "Joel's Site")
    (setq org-static-blog-publish-url "https://blog.joelg.cf/")
    (setq org-static-blog-publish-directory "/backup/home/joel/Downloads/Chizi123.github.io/")
    (setq org-static-blog-posts-directory "/backup/home/joel/Downloads/Chizi123.github.io/posts/")
    (setq org-static-blog-drafts-directory "/backup/home/joel/Downloads/Chizi123.github.io/drafts/")
    (setq org-static-blog-enable-tags t)
    (setq org-export-with-toc nil)
    (setq org-export-with-section-numbers nil)
    ;; This header is inserted into the <head> section of every page:
    ;;   (you will need to create the style sheet at
    ;;    ~/projects/blog/static/style.css
    ;;    and the favicon at
    ;;    ~/projects/blog/static/favicon.ico)
    (setq org-static-blog-page-header
    "<meta name=\"author\" content=\"Joel Grunbaum\">
    <meta name=\"referrer\" content=\"no-referrer\">
    <link href= \"static/style.css\" rel=\"stylesheet\" type=\"text/css\" />
    <link rel=\"icon\" href=\"static/favicon.png\">
    <script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-147303155-2\"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-147303155-2');
    </script>
    ")
    ;; This preamble is inserted at the beginning of the <body> of every page:
    ;;   This particular HTML creates a <div> with a simple linked headline
    (setq org-static-blog-page-preamble
    "<div class=\"header\">
      <a href=\"https://blog.joelg.cf\">Joel's Site - Personal site and constant work in progress</a>
      <div class=\"sitelinks\">
        <a href=\"https://blog.joelg.cf/about-me.html\">About Me</a> |
        <a href=\"https://github.com/Chizi123\">Github</a> |
        <a href=\"https://facebook.com/joel.grun.5\">Facebook</a>
      </div>
    </div>")
    ;; This postamble is inserted at the end of the <body> of every page:
    ;;   This particular HTML creates a <div> with a link to the archive page
    ;;   and a licensing stub.
    (setq org-static-blog-page-postamble
    "<div id=\"archive\">
      <a href=\"https://blog.joelg.cf/archive.html\">Other posts</a>
    </div>
    <br>
    <div id=\"commento\"></div>
    <script src=\"https://cdn.commento.io/js/commento.js\"></script>")
    ;; <center><button id=\"disqus_button\" onclick=\"load_disqus()\">Load Disqus Comments</button></center>
    ;; <div id=\"disqus_thread\"></div>
    ;; <script type=\"text/javascript\">
    ;;   function load_disqus() {
    ;;       var dsq = document.createElement('script');
    ;;       dsq.type = 'text/javascript';
    ;;       dsq.async = true;
    ;;       dsq.src = 'https://joelg-cf.disqus.com/embed.js';
    ;;       (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    ;;       document.getElementById('disqus_button').style.visibility = 'hidden';
    ;;   };
    ;; </script>")
    ;; generate blog files and create sitemap for files
    (defun blog-publish()
      (interactive)
      (org-static-blog-publish)
      (setq n 0)
      (setq site "https://blog.joelg.cf/")
      (setq posts (directory-files org-static-blog-publish-directory))
      (generate-new-buffer "sitemap.xml.gen")
      (with-current-buffer "sitemap.xml.gen" (insert "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"))
      (while (< n (length (directory-files org-static-blog-publish-directory)))
        (setq curr (nth n posts))
        (if (string-match "\\(html\\)" curr)
            (if (string-match "index.html" curr)
                (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site "</loc>\n\t</url>\n")))
              (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site curr "</loc>\n\t</url>\n")))))
        (setq n (1+ n)))
      (with-current-buffer "sitemap.xml.gen" (insert "</urlset>"))
      (with-current-buffer "sitemap.xml.gen" (write-region (point-min) (point-max) (concat org-static-blog-publish-directory "sitemap.xml")) t)
      (kill-buffer "sitemap.xml.gen"))
  )
#+END_SRC
** Emacs-htmlize
Allow org features to be exported to HTML for site
#+BEGIN_SRC emacs-lisp
  (use-package htmlize
    :ensure t)
#+END_SRC