Skip to content

Emacs configuration for the NB-Casts virtual machine

Notifications You must be signed in to change notification settings

nbcasts/emacs-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emacs configuration

Auto update packages

(use-package auto-package-update :ensure t)

Global keybindings

(global-set-key (kbd "H-k") 'global-set-key)

Files

(global-set-key (kbd "H-s") 'save-buffer)
(global-set-key (kbd "H-S") 'save-some-buffers)

(global-set-key (kbd "H-f") 'fdx/visit-or-projectile-visit)
(global-set-key (kbd "H-F") 'ido-find-file)

(global-set-key (kbd "H-D f") 'fdx/delete-file-and-buffer)
(global-set-key (kbd "H-D r") 'fdx/rename-current-file)
(global-set-key (kbd "H-D m") 'fdx/chmod-current-file)
(global-set-key (kbd "H-D t") 'fdx/touch-current-file)

Lines

(global-set-key (kbd "H--") 'kill-whole-line)

(global-set-key (kbd "H-d") 'fdx/duplicate-line)

(global-set-key (kbd "<H-S-up>") 'fdx/move-line-up)
(global-set-key (kbd "<H-S-down>") 'fdx/move-line-down)

Buffer

Auto revert buffers

(global-auto-revert-mode 1)

Reload file with <f5>

(global-set-key (kbd "<f5>") 'revert-buffer)

Reloading config

(defun fdx/reload-emacs-configuration ()
  "Reload emacs configuration"
  (interactive)
  (org-babel-load-file (expand-file-name "~/.emacs.d/Readme.org")))

(global-set-key (kbd "<H-f12>") 'fdx/reload-emacs-configuration)

(global-set-key (kbd "S-<f12>") 'package-refresh-contents)

Word and line wrap

(setq-default toggle-truncate-lines t)
(setq-default word-wrap t)

Interface tweaks

(setq inhibit-startup-message t)
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

;; (menu-bar-mode 1)

(fset 'yes-or-no-p 'y-or-n-p)
(blink-cursor-mode 0)

(show-paren-mode)

Appearance

Doom

(use-package doom-themes :ensure t)

Load theme

(load-theme 'doom-ir-black t)

Default face

(custom-set-faces
 `(default ((t (:family "Inconsolata"
                        ;; :foundry "unknown"
                        :slant normal
                        :weight normal
                        :height ,260
                        :width normal)))))

Try

(use-package try :ensure t)

Which key

(use-package which-key
  :ensure t
  :config (which-key-mode))

Backup files

Save backup files in it’s own directory

(setq backup-directory-alist `(("." . "~/.emacs.d/backup-files")))

Set backup by copying

(setq backup-by-copying t)

Configure how much to backup

(setq delete-old-versions t
      kept-new-versions 6
      kept-old-versions 2
      version-control t)

Indentation

Reindending whole buffer

;;;###autoload
(defun fdx/reindent-buffer ()
  "Indent the current buffer."
  (interactive)
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max))
  (untabify (point-min) (point-max)))

Global keybinding

(global-set-key (kbd "H-=") 'fdx/reindent-buffer)

Highlight current indent level

(use-package indent-guide
  :ensure t
  :config
  (progn

    ))

(require 'indent-guide)

Highlight indentation level

(use-package highlight-indent-guides
  :ensure t
  :init
  (progn
    (setq highlight-indent-guides-method 'fill)
    (setq highlight-indent-guides-auto-odd-face-perc 2)
    (setq highlight-indent-guides-auto-even-face-perc 5)
    ))

(require 'highlight-indent-guides)

Set default indentation level

(setq         indent-tabs-mode nil) ; And force use of spaces
(setq-default indent-tabs-mode nil)

(setq c-basic-offset          2) ; indents 2 chars
(setq tab-width               2) ; and 2 char wide for TAB

(setq css-indent-offset       2) ; set CSS indentation to 2 spaces
(setq js-indent-level         2) ; set JavaScript indentation to 2 spaces
(setq coffee-tab-width        2) ; set CoffeeScript indentation to 2 spaces
(setq typescript-indent-level 2) ; set TypeScript indentation to 2 spaces

Align regex

(global-set-key (kbd "C-c i") 'align-regexp)

Cleanup whitespace mode

(use-package whitespace-cleanup-mode :ensure t)

org-mode

Blocks

Custom block templates

(setq org-structure-template-alist
      '(
        ("-" . "src")
        ("q" . "quote")
        ("v" . "verse")
        ("r" . "src ruby")
        ("l" . "src emacs-lisp")
        ("s" . "src sh")
        ("C" . "comment")
        ("e" . "example")
        ("h" . "export html")
        ("a" . "export ascii")
        ("c" . "center")
        ("E" . "export")
        ))

Clocking

(setq org-clock-into-drawer "CLOCKING")

(setq org-duration-format (quote h:mm))

Org bullets

Pretty bullets for org-mode

(use-package org-bullets
  :ensure t
  :config
  (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

Populate org-mode shots

;;;###autoload
(defun fdx/populate-org-shots (ARG)
  "Populate {{{shot(n)}}}* macros on current buffer"
  (interactive "p")
  (save-excursion
    (beginning-of-buffer)
    (kmacro-set-counter 1)
    (while (search-forward "{{{shot(" nil t)
      (kmacro-insert-counter ARG)
      (let ((start (point)))
        (search-forward-regexp "\\(,\.+)\\|)}}}\\)")
        (let ((end (match-beginning 0)))
          (delete-region start end)
          )
        ))))

Insert shot and populate

;;;###autoload
(defun fdx/insert-and-populate-org-shots ()
  "Insert {{{shot()}}} and repopulate shots on buffer"
  (interactive)
  (insert "{{{shot()}}}")
  (fdx/populate-org-shots t))

Org Agenda

(global-set-key (kbd "H-a g") 'org-agenda)

Projectile

(use-package projectile :ensure t)

Projectile-sensitive commands

Find file

;;;###autoload
(defun fdx/visit-or-projectile-visit (&optional a b)
  (interactive)
  (if (projectile-project-p)
      (call-interactively #'counsel-projectile-find-file)
    (call-interactively #'counsel-find-file)))

ag

;;;###autoload
(defun fdx/ag-or-projectile-ag (&optional a b)
  (interactive)
  (if (projectile-project-p)
      (call-interactively #'projectile-ag)
    (call-interactively #'ag)))

Searching

Keybindings

(global-set-key (kbd "H-g") 'projectile-ripgrep)
(global-set-key (kbd "H-G") 'ag)

Silversearcher ag

(use-package ag :ensure t)

Reuse buffer

(setq ag-reuse-buffers t)

ripgrep

(use-package ripgrep :ensure t)

Wgrep

(use-package wgrep :ensure t)
(use-package wgrep-ag :ensure t)
(require 'wgrep)
(require 'wgrep-ag)

Auto save wgrep buffer

(setq wgrep-auto-save-buffer t)

Magit

(use-package magit :ensure t)

Keybindings

(global-set-key (kbd "C-c g") 'magit-status)
(global-set-key (kbd "C-c C-g") 'magit-status)

Full screen magit-status and unfold all sections

(defadvice magit-status (around magit-fullscreen activate)
  (window-configuration-to-register :magit-fullscreen)
  ad-do-it
  (delete-other-windows)
  (magit-section-show-level-2-all))

Restore windows after quitting magit

(defun magit-quit-session ()
  "Restores the previous window configuration and kills the magit buffer"
  (interactive)
  (kill-buffer)
  (jump-to-register :magit-fullscreen))
(define-key magit-status-mode-map (kbd "q") 'magit-quit-session)

Some custom variables

(custom-set-variables
 '(git-commit-fill-column 1000)
 '(git-commit-finish-query-functions nil)
 '(git-commit-summary-max-length 1000))

Git

Timemachine

(use-package git-timemachine :ensure t)

Dired

Open files with “a”

(put 'dired-find-alternate-file 'disabled nil)

Auto refresh dired, but be quiet about it

(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)

Jump to top and bottom

(defun dired-back-to-top ()
  (interactive)
  (beginning-of-buffer)
  (dired-next-line 1)
  (dired-next-line 1)
  (dired-next-line 1))

(define-key dired-mode-map
            (vector 'remap 'beginning-of-buffer) 'dired-back-to-top)

(defun dired-jump-to-bottom ()
  (interactive)
  (end-of-buffer)
  (dired-next-line -1))

(define-key dired-mode-map
            (vector 'remap 'end-of-buffer) 'dired-jump-to-bottom)

File ordering

(setq dired-listing-switches "-aBhl  --group-directories-first")

Dired omit

(setq-default dired-omit-files-p nil) ; Buffer-local variable

(setq dired-omit-files "^\\.?#\\|^\\.$\\|^\\.[^\\.]")
;; (setq dired-omit-mode t) ; Turn on Omit mode.
(setq dired-omit-verbose nil) ; Turn off Omit mode messages.

dired-x

(require 'dired-x)

Hide details

(add-hook 'dired-mode-hook
          (lambda ()
            (dired-hide-details-mode t)))

Buffers

Kill other buffers

Kill all buffers except for the current one

;;;###autoload
(defun fdx/kill-other-buffers ()
  "Kill all buffers but the current one.
Don't mess with special buffers."
  (interactive)
  (dolist (buffer (buffer-list))
    (unless (or (eql buffer (current-buffer)) (not (buffer-file-name buffer)))
      (progn
        (kill-buffer buffer)
        ))
    (delete-other-windows)))

Bind it to C-c k

(global-set-key (kbd "C-c k") 'fdx/kill-other-buffers)

Switch to scratch buffer

(global-set-key (kbd "C-x C-w")
                (lambda ()
                  (interactive)
                  (switch-to-buffer "*scratch*")))

Reuse buffers

All buffers, try to reuse windows across all frames

Source

(defun fdx/reuse-buffers ()
  (interactive)
  (add-to-list 'display-buffer-alist
               '(".*". (display-buffer-reuse-window .
                                                    ((reusable-frames . t))))))

Directories

When finding a file, if the parent directory doesn’t exist, create it first

;; Make directories on the fly
(defun make-parent-directory ()
  "Make sure the directory of `buffer-file-name' exists."
  (make-directory (file-name-directory buffer-file-name) t))

(add-hook 'find-file-not-found-functions #'make-parent-directory)

Windows

Global keybindings

(global-set-key (kbd "H-<left>")  'windmove-left)
(global-set-key (kbd "H-<right>") 'windmove-right)
(global-set-key (kbd "H-<up>")    'windmove-up)
(global-set-key (kbd "H-<down>")  'windmove-down)

(global-set-key (kbd "H-w") 'balance-windows)

Winner mode

Navigate window configuration history

(winner-mode 1)

Centered cursor mode

(use-package centered-cursor-mode :ensure t)

Split vertically by default

(setq split-width-threshold 0)
(setq split-height-threshold nil)

Ruby

Local keybindings

(eval-after-load "ruby-mode"
  '(progn
     (define-key ruby-mode-map (kbd "C-c C-c") 'fdx/seeing-is-believing-run-as-xmpfilter-and-reload-mode)
     (define-key ruby-mode-map (kbd "H-;") 'fdx/comment-dwim)
     (define-key ruby-mode-map (kbd "C-;") 'fdx/comment-dwim)
     (define-key ruby-mode-map (kbd "H-=") 'fdx/reindent-buffer)
     (define-key ruby-mode-map (kbd "C-c C-c") 'xmp)
     (define-key ruby-mode-map (kbd "C-c c") 'xmp)
     (define-key ruby-mode-map (kbd "C-;") 'comment-dwim)
     ))

XMP

(load
 (expand-file-name "~/.emacs.d/fdx/vendor/rcodetools.el")
 t)

(setq xmpfilter-command-name
      "ruby -S seeing_is_believing --xmpfilter-style")
;; (setq xmpfilter-command-name
;;       "ruby -S seeing_is_believing -r ~/lib/xmp_base --xmpfilter-style")

RVM

(use-package rvm
  :ensure t
  :config
  (rvm-use-default))

Rspec

(use-package rspec-mode
  :bind (
         ("H-r r"   . rspec-rerun)
         ("H-r t"   . rspec-toggle-spec-and-target)
         ("H-r v"   . rspec-verify)
         ("H-r a"   . rspec-verify-all)
         ("H-r H-a" . rspec-verify-all)
         ("H-r s"   . rspec-verify-single)
         ("H-r f"   . rspec-run-last-failed)
         )
  :ensure t)

Ruby Runner Mode

(load (expand-file-name "~/.emacs.d/fdx/vendor/ruby-runner-mode/ruby-runner-mode.el") t)

Functions and Keybindings

(global-set-key (kbd "H-i i") 'rr/rerun)

(which-key-add-key-based-replacements "H-i r" "RSpec")
(rr/global-set-key "H-i r a" "bundle exec rspec")
;; (rr/global-set-key-current-file "H-i r v" "rspec")
;; (rr/global-set-key-current-file "H-6" "rspec")

(which-key-add-key-based-replacements "H-i u" "Rubocop")
(rr/global-set-key "H-i u a" "bundle exec rubocop")
(rr/global-set-key "H-i u A" "bundle exec rubocop --autocorrect && bundle exec rubocop")
(rr/global-set-key "H-i u T" "bundle exec rubocop --regenerate-todo")

(which-key-add-key-based-replacements "H-i b" "Bundle")
(rr/global-set-key-multiple "H-i b b" '("bundle install" "pessimize -c patch --no-backup" "bundle install"))
(rr/global-set-key-multiple "H-i b B" '("bundle update" "pessimize -c patch --no-backup" "bundle install"))

;; (rr/global-set-key "H-i r" "ruby" (buffer-file-name)) <- this doesn't work

Parens

(use-package ruby-electric :ensure t)

(require 'ruby-electric)
(electric-pair-mode t)

Bundle

;;;###autoload
(defun fdx/bundle ()
  "Run Pessimize."
  (interactive)
  (compile "bundle install"))

;;;###autoload
(defun fdx/bundle-update ()
  "Run Pessimize."
  (interactive)
  (compile "bundle update"))

;;;###autoload
(defun fdx/pessimize ()
  "Run Pessimize."
  (interactive)
  (compile "pessimize -c patch --no-backup"))

;;;###autoload
(defun fdx/bundle-pessimize ()
  "Run bundel install and pessimize."
  (interactive)
  (compile "bundle install && pessimize -c patch --no-backup"))

;;;###autoload
(defun fdx/bundle-update-pessimize ()
  "Run bundle update and pessimize."
  (interactive)
  (compile "bundle update && pessimize -c patch --no-backup"))

;;;###autoload
(defun fdx/rspec-init ()
  "Run bundle update and pessimize."
  (interactive)
  (compile "bundle exec rspec --init"))

Inline Ruby namespace

Convert a nested set of classes and modules to one line with the namespace joined by “::”

;;;###autoload
(defun fdx/inline-ruby-namespace (beg end)
  (interactive "r")

  (let ((selection (buffer-substring-no-properties beg end)))
    (let
        ((inlined (string-join (split-string (s-replace "\n" "" selection) "\s*\\(?:module\\|class\\)\s+") "::")))
      ;;(message selection)
      (message inlined)
      (delete-region beg end)
      (insert inlined)

      )

    )
  )

Refactorings

(use-package ruby-refactor :ensure t)

Don’t use flymake

(setq ruby-flymake-use-rubocop-if-available nil)

Clean whitespace

(add-hook 'before-save-hook 'whitespace-cleanup)

Counsel

(use-package counsel :ensure t)

Remove caret

(setq ivy-initial-inputs-alist nil)

Flex

(setq ivy-re-builders-alist '((swiper . ivy--regex-plus)
                              (t . ivy--regex-fuzzy)))

Counsel-projectile

(use-package counsel-projectile :ensure t)

Swiper

(use-package swiper
  :ensure t
  :bind (
         ("C-s" . swiper)
         ("C-r" . swiper)
         ("C-c C-r" . ivy-resume)
         ("M-x" . counsel-M-x)
         ("C-x C-f" . counsel-find-file)
         )
  :config
  (progn
    (ivy-mode 1)
    (setq ivy-use-virtual-buffers t)
    (setq enable-recursive-minibuffers t)
    (global-set-key (kbd "<f1> f") 'counsel-describe-function)
    (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
    (global-set-key (kbd "<f1> l") 'counsel-find-library)
    (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
    (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
    (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
    ))

Ivy

(use-package ivy
  :ensure t
  :config
  (require 'ivy))

(use-package flx
  :ensure t
  :config
  (require 'flx))

(setq ivy-use-virtual-buffers t)

;; intentional space before end of string
(setq ivy-count-format "(%d/%d) ")
(setq ivy-initial-inputs-alist nil)

(setq ivy-re-builders-alist
      '((swiper . ivy--regex-plus)
        (t      . ivy--regex-fuzzy)))

;; Use C-j for immediate termination with current value
(define-key ivy-minibuffer-map (kbd "C-j") #'ivy-immediate-done)
;; Use RET for continuing completion for that directory
(define-key ivy-minibuffer-map (kbd "RET") #'ivy-alt-done)

(ivy-mode 1)

Snippets

(use-package yasnippet
  :ensure t
  :init
  (progn
    (setq yas-snippet-dirs
          (list (expand-file-name "~/.emacs.d/fdx/snippets")))
    (yas-global-mode 1)
    ))

(require 'yasnippet)

Recompile snippets

;;;###autoload
(defun fdx/recompile-snippets ()
  (interactive)
  (shell-command
   (concat "rm -rf "
           user-emacs-directory
           "fdx/snippets/**/.yas-compiled-snippets.el*"))
  (yas/recompile-all)
  (yas/reload-all))

Some keybindings

(global-set-key (kbd "S-<f7>") 'fdx/recompile-snippets)
(global-set-key (kbd "<backtab>") 'yas-expand-from-trigger-key)
(global-set-key (kbd "C-<tab>") 'yas-insert-snippet)

Undo tree

(use-package undo-tree
  :ensure t
  :init
  (global-undo-tree-mode))

Don’t save undo-tree history

(setq undo-tree-auto-save-history nil)

Bookmarks

(global-set-key (kbd "H-0") 'bookmark-jump)
(global-set-key (kbd "H-)") 'bookmark-set)

web-mode

(use-package web-mode :ensure t)

Emmet mode

(use-package emmet-mode :ensure t)

Slim

(use-package slim-mode
  :bind (
         ("H-h" . emmet-expand-yas)
         ("H-=" . fdx/reindent-buffer)
         )
  :ensure t)

Join line

(global-set-key (kbd "H-j") (lambda ()
                              (interactive)
                              (join-line -1)))

Very large files

(use-package vlf :ensure t)

ASCII Doc

(use-package adoc-mode :ensure t)
(add-hook 'adoc-mode-hook (lambda()
                            (buffer-face-mode -1)
                            (global-set-key (kbd "C-c t t") 'fdx/populate-adoc-shots)))

Populate ASCIIdoc shots

;;;###autoload
(defun fdx/populate-adoc-shots (ARG)
  "Populate {{{shot(n)}}} macros on current buffer"
  (interactive "p")
  (save-excursion
    (beginning-of-buffer)
    (kmacro-set-counter 1)
    (while (search-forward "shot::[" nil t)
      (let ((start (point)))
        (search-forward-regexp ",\\|]" nil nil)
        (left-char)
        (delete-region start (point)))
      (kmacro-insert-counter ARG))
    (message "Done populating shot macros.")))
;;;###autoload
(defun fdx/insert-and-populate-adoc-shots ()
  "Insert {{{shot()}}} and repopulate shots on buffer"
  (interactive)
  (insert "shot::[]")
  (fdx/populate-adoc-shots t))

Markdown

Populate markdown shots

;;;###autoload
(defun fdx/populate-md-shots (ARG)
  "Populate <!-- shot(n) --> macros on current buffer"
  (interactive "p")
  (save-excursion
    (beginning-of-buffer)
    (kmacro-set-counter 1)
    (while (search-forward "<!-- shot(" nil t)
      (let ((start (point)))
        (search-forward-regexp ",\\|)" nil nil)
        (left-char)
        (delete-region start (point)))
      (kmacro-insert-counter ARG))
    (message "Done populating shot macros.")))
;;;###autoload
(defun fdx/insert-and-populate-md-shots ()
  "Insert {{{shot()}}} and repopulate shots on buffer"
  (interactive)
  (insert "<!-- shot() -->")
  (fdx/populate-md-shots t))

Populate HanamiMastery shots

;;;###autoload
(defun fdx/populate-hm-shots (ARG)
  "Populate [đź“˝ nw] macros on current buffer"
  (interactive "p")
  (save-excursion
    (beginning-of-buffer)
    (kmacro-set-counter 1)
    (while (search-forward "[đź“˝ " nil t)
      (let ((start (point)))
        (search-forward-regexp ",\\|]" nil nil)
        (left-char)
        (delete-region start (point)))
      (kmacro-insert-counter ARG))
    (message "Done populating shots.")))
;;;###autoload
(defun fdx/insert-and-populate-hm-shots ()
  "Insert [đź“˝ ] and repopulate shots on buffer"
  (interactive)
  (insert "[đź“˝ ]")
  (fdx/populate-hm-shots t))

Columns

Show column numbers

(column-number-mode)

Font size customizations

(setq fdx/font-size-increment 5)

;;;###autoload
(defun fdx/decrease-font ()
  "Decrease the font for all buffers"
  (interactive)
  (let ((old-face-attribute (face-attribute 'default :height)))
    (set-face-attribute 'default nil :height (+ old-face-attribute fdx/font-size-increment))))

;;;###autoload
(defun fdx/increase-font ()
  "Increase the font for all buffers"
  (interactive)
  (let ((old-face-attribute (face-attribute 'default :height)))
    (set-face-attribute 'default nil :height (- old-face-attribute fdx/font-size-increment))))

Key Bindings

(global-set-key (kbd "H-]") 'fdx/increase-font)
(global-set-key (kbd "H-[") 'fdx/decrease-font)

No op

(defun no-op () (interactive))

Multiple cursors

(use-package multiple-cursors :ensure t)

(require 'multiple-cursors)

Keybindings

(global-set-key (kbd "C-c C-a") 'mc/edit-lines)
(global-set-key (kbd "C-M-<return>") 'mc/edit-lines)

(global-set-key (kbd "C-c a") 'mc/mark-all-like-this)

(global-set-key (kbd "H-.") 'mc/mark-next-like-this)
(global-set-key (kbd "H-,") 'mc/mark-previous-like-this)
(global-set-key (kbd "H->") 'mc/skip-to-next-like-this)

(global-set-key (kbd "H-p") 'mc/insert-numbers)

Expand region

(use-package expand-region :ensure t)

(require 'expand-region)

(setq expand-region-fast-keys-enabled nil)

Keybindings

(global-set-key (kbd "H-e") 'er/expand-region)
(global-set-key (kbd "C-c e") 'er/expand-region)

Reload browser

;;;###autoload
(defun fdx/reload-browser (&optional by)
  "Reload web browser"
  (interactive)
  (save-some-buffers)
  (save-window-excursion (async-shell-command "~/bin/reload-browser"))
  ;; (kill-buffer "*Async Shell Command*")
  )

;;;###autoload
(defun fdx/send-up-enter-to-current-window (&optional list)
  "Reload web browser"
  (interactive)
  (save-some-buffers)
  (save-window-excursion (async-shell-command "~/bin/send_to_current_window \"<Up>\" \"<Return>\""))
  ;; (kill-buffer "*Async Shell Command*")
  )

;;;###autoload
(defun fdx/set-current-window (&optional by)
  "Reload web browser"
  (interactive)
  (save-some-buffers)
  (save-window-excursion (async-shell-command "~/bin/set_current_window"))
  ;; (kill-buffer "*Async Shell Command*")
  )

;;;###autoload
(defun fdx/save-and-reload-browser (&optional by)
  "Save current buffer and reload web browser"
  (interactive)
  (save-buffer)
  (fdx/reload-browser)
  )

;;;###autoload
(defun fdx/save-and-reload-browser-with-delay (&optional by)
  "Save current buffer and reload web browser"
  (interactive)
  (save-buffer)
  (sleep-for 0.3)
  (fdx/reload-browser)
  )

;;;###autoload
(defun fdx/save-recompile-and-reload-browser-with-delay (&optional by)
  "Save current buffer and reload web browser"
  (interactive)
  (save-buffer)
  (recompile)
  (sleep-for 2.5)
  (fdx/reload-browser)
  )

Toggle Window Split

Toggle window splits between vertical and horizontal splits

;;;###autoload
(defun fdx/toggle-window-split ()
  (interactive)
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
             (next-win-buffer (window-buffer (next-window)))
             (this-win-edges (window-edges (selected-window)))
             (next-win-edges (window-edges (next-window)))
             (this-win-2nd (not (and (<= (car this-win-edges)
                                         (car next-win-edges))
                                     (<= (cadr this-win-edges)
                                         (cadr next-win-edges)))))
             (splitter
              (if (= (car this-win-edges)
                     (car (window-edges (next-window))))
                  'split-window-horizontally
                'split-window-vertically)))
        (delete-other-windows)
        (let ((first-win (selected-window)))
          (funcall splitter)
          (if this-win-2nd (other-window 1))
          (set-window-buffer (selected-window) this-win-buffer)
          (set-window-buffer (next-window) next-win-buffer)
          (select-window first-win)
          (if this-win-2nd (other-window 1))))))

Keybinding

(global-set-key (kbd "C-x /") 'fdx/toggle-window-split)

Countdown

(use-package countdown :ensure t)

Compilation

Keybindings

(global-set-key (kbd "H-m") 'recompile)
(global-set-key (kbd "H-b") 'compile)

Compile (run) current file

(defun fdx/run-current-file ()
  (interactive)
  (save-buffer)
  (compile (buffer-file-name)))

Compile (run) current Ruby file

(defun fdx/run-current-ruby-file ()
  (interactive)
  (save-buffer)
  (compile (concat "ruby " (buffer-file-name))))

Copy current file name to clipboard

;;;###autoload
(defun fdx/file-name-to-clipboard ()
  "Copy current file name to clipboard"
  (interactive)
  (if (buffer-file-name)
      (progn
        (kill-new (buffer-file-name))
        (message (buffer-file-name))
        )
    (message "Current buffer is not visiting a saved file")
    )
  )

Docker

(use-package dockerfile-mode :ensure t)

YAML

(use-package yaml-mode :ensure t)

Cucumber School

Run rake tasks

(defun fdx/cucumber/run-rake-task(task)
  (shell-command
   (concat "cd /data/cucumber/content/ && bundle exec rake " task)
   )
  )

(defun fdx/cucumber/run-code-rake-task()
  (interactive)
  (fdx/cucumber/run-rake-task "code")
  )

(defun fdx/cucumber/run-html-rake-task()
  (interactive)
  (fdx/cucumber/run-rake-task "html")
  )

(defun fdx/cucumber/run-html-rake-task-and-reload-browser()
  (interactive)
  (fdx/populate-adoc-shots 1)
  (save-buffer)
  (fdx/cucumber/run-rake-task "html")
                                        ; (sleep-for 0.5)
  (fdx/reload-browser)
  )

ASCII Doc

(use-package adoc-mode :ensure t)
(add-hook 'adoc-mode-hook (lambda()
                            (buffer-face-mode t)
                            (global-set-key (kbd "C-c t t") 'fdx/populate-adoc-shots)))

Copy include line from file

(defun fdx/adoc-copy-include-line-from-file (p m)
  (interactive "r")

  (let* (
         (lines-arg (fdx/adoc-get-lines-arg p m))
         (file (fdx/adoc-strip-src-file-name (buffer-file-name)))
         )

    (kill-new (concat "include::" file "[" lines-arg "]"))
    (message (concat "include::" file "[" lines-arg "]"))
    )
  )

(defun fdx/adoc-get-lines-arg (p m)
  (if (region-active-p)
      (if (eq p m)
          (format "lines=%s" (line-number-at-pos p) (line-number-at-pos m))
        (format "lines=%s..%s" (line-number-at-pos p) (line-number-at-pos m)))
    )
  )

(defun fdx/adoc-strip-src-file-name (file-name)
  (replace-regexp-in-string "\\(\.\+/[0-9][0-9]/\\)" "../" (buffer-file-name) nil nil 1)
  )

Editing tweaks

Delete selection

(delete-selection-mode 1)

Lines

Line numbers

(global-display-line-numbers-mode 0)
(display-line-numbers-mode 0)

Highlight current line

(global-hl-line-mode 1)

Duplicate line

;;;###autoload
(defun fdx/duplicate-line()
  (interactive)
  (move-beginning-of-line 1)
  (kill-line)
  (yank)
  (open-line 1)
  (next-line 1)
  (yank))

Move lines around

;;;###autoload
(defun fdx/move-line-up ()
  "Move up the current line."
  (interactive)
  (transpose-lines 1)
  (forward-line -2)
  (indent-according-to-mode))

;;;###autoload
(defun fdx/move-line-down ()
  "Move down the current line."
  (interactive)
  (forward-line 1)
  (transpose-lines 1)
  (forward-line -1)
  (indent-according-to-mode))

Open lines above and below

Commands for opening a new line above and below the current line

;;;###autoload
(defun fdx/open-line-below ()
  "Open an empty line above the current one and move."
  (interactive)
  (move-end-of-line nil)
  (newline-and-indent))

;;;###autoload
(defun fdx/open-line-above ()
  "Open an empty line above the current one and move."
  (interactive)
  (move-beginning-of-line nil)
  (newline-and-indent)
  (forward-line -1)
  (indent-according-to-mode))

Bind them

(global-set-key (kbd "C-<return>") 'fdx/open-line-below)
(global-set-key (kbd "C-S-<return>") 'fdx/open-line-above)

Strings

Replace tabs with commas

(defun fdx/paste-replacing-tabs-with-commas ()
  (interactive)
  (insert (replace-regexp-in-string "\t" "," (car kill-ring)))
  )

Dead characters

(require 'iso-transl)

Files tweaks

Save place of cursor between sessions

(save-place-mode 1)

Backup files

Write backup files to own directory

(setq backup-directory-alist
      `(("." . ,(expand-file-name
                 (expand-file-name "~/.emacs.d/backups")))))

Make backups of files, even when they’re in version control

(setq vc-make-backup-files t)
(setq create-lockfiles nil)

Rename current file

;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun fdx/rename-current-file (new-name)
  "Renames both current buffer and file it's visiting to NEW-NAME."
  (interactive (list (read-string "sNew name: " (file-name-nondirectory (buffer-file-name)))))
  (let ((name (buffer-name))
        (filename (buffer-file-name)))
    (if (not filename)
        (message "Buffer '%s' is not visiting a file!" name)
      (if (get-buffer new-name)
          (message "A buffer named '%s' already exists!" new-name)
        (progn
          (rename-file filename new-name 1)
          (rename-buffer new-name)
          (set-visited-file-name new-name)
          (set-buffer-modified-p nil))))))

Delete current file

;;;###autoload
(defun fdx/delete-file-and-buffer ()
  "Kill the current buffer and deletes the file it is visiting."
  (interactive)
  (let ((filename (buffer-file-name)))
    (when filename
      (if (vc-backend filename)
          (vc-delete-file filename)
        (progn
          (delete-file filename)
          (message "Deleted file %s" filename)
          (kill-buffer))))))

Touch current file

(defun fdx/touch-current-file ()
  "updates mtime on the file for the current buffer"
  (interactive)
  (shell-command (concat "touch " (shell-quote-argument (buffer-file-name))))
  (clear-visited-file-modtime))

Change mode to current file

(defun fdx/chmod-current-file ()
  "updates mtime on the file for the current buffer"
  (interactive)
  (chmod (buffer-file-name) (read-file-modes)))

Company

(use-package company :ensure t)

LSP

(use-package lsp-mode :ensure t)

Languages

Ruby

(add-hook 'ruby-mode-hook #'lsp)
;; (add-hook 'ruby-mode-hook #'lsp-deferred)

Tabnine

(use-package company-tabnine :ensure t)

Add to company

(add-to-list 'company-backends #'company-tabnine)

Ruby Framework generator

Just Ruby

(defun fdx/generate_ruby_framework_project (project-name)
  "Reload web browser"
  (interactive "sProject name: ")
  (message (concat "Generating project " project-name))
  (save-some-buffers)
  (save-window-excursion (async-shell-command (concat "~/bin/ruby_framework " project-name)))
  )

Web with Roda

(defun fdx/generate_ruby_framework_web_project (project-name)
  "Reload web browser"
  (interactive "sProject name: ")
  (message (concat "Generating project " project-name))
  (save-some-buffers)
  (save-window-excursion (async-shell-command (concat "~/bin/ruby_framework_web " project-name)))
  )

Directory local variables

Source

TypeScript

(use-package typescript-mode :ensure t)

Start Server

(server-start)

Folding

(use-package yafolding :ensure t)

(global-set-key (kbd "H-c") 'yafolding-toggle-element)
(global-set-key (kbd "H-C") 'yafolding-toggle-all)

Colors in compilation buffer

Display ANSI colors on current buffer

(require 'ansi-color)
(defun fdx/display-ansi-colors ()
  (interactive)
  (ansi-color-apply-on-region (point-min) (point-max)))

Display ANSI colors on compilation buffer

(require 'ansi-color)
(defun endless/colorize-compilation ()
  "Colorize from 'compilation-filter-start' to 'point'."
  (let ((inhibit-read-only t))
    (ansi-color-apply-on-region
     compilation-filter-start (point))))

(add-hook 'compilation-filter-hook
          'endless/colorize-compilation)

Fix ANSII colors

(use-package xterm-color :ensure t)
(require 'xterm-color)
(setq compilation-environment '("TERM=xterm-256color"))
(defun my/advice-compilation-filter (f proc string)
  (funcall f proc (xterm-color-filter string)))
(advice-add 'compilation-filter :around #'my/advice-compilation-filter)

Set TERM environment variable to show colors on terminal

(setenv "TERM" "256colors")

Org livemarkup

(load
 (expand-file-name "~/.emacs.d/fdx/vendor/livemarkup.el")
 t)
(setq livemarkup-output-directory "/sandbox"
      livemarkup-close-buffer-delete-temp-files t
      livemarkup-refresh-interval 0.1
      livemarkup-browser-open-function t)

Flet

(use-package noflet :ensure t :defer t)

File extensions

(add-to-list 'auto-mode-alist '("\\.org\\'"      . org-mode))
(add-to-list 'auto-mode-alist '("\\.rb\\'"       . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile\\'"    . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rake\\'"     . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ru\\'"       . ruby-mode))
(add-to-list 'auto-mode-alist '("Gemfile\\'"     . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gemspec\\'"  . ruby-mode))
(add-to-list 'auto-mode-alist '("Guardfile\\'"   . ruby-mode))
(add-to-list 'auto-mode-alist '("Jenkinsfile\\'" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rabl\\'"     . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.env"         . ruby-mode))

(add-to-list 'auto-mode-alist '("\\.html\\'"     . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'"      . web-mode))

(add-to-list 'auto-mode-alist (cons "\\.adoc\\'" 'adoc-mode))

(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode))

About

Emacs configuration for the NB-Casts virtual machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published