From 8d3905466d75cbdfd9777cc02a40ea30d5802e35 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 20 Mar 2017 12:42:23 +0100 Subject: emacs: fixed find-file advice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It failed for directories opened in dired mode. Signed-off-by: Miquel Sabaté Solà --- emacs/init.html | 432 +++++++++++++++++++++++++++++++++++++++++--------------- emacs/init.org | 4 +- 2 files changed, 322 insertions(+), 114 deletions(-) (limited to 'emacs') diff --git a/emacs/init.html b/emacs/init.html index 2687495..233ad64 100644 --- a/emacs/init.html +++ b/emacs/init.html @@ -4,7 +4,7 @@ mssola's GNU Emacs configuration - + @@ -164,41 +164,42 @@ for the JavaScript code in this tag.
  • Project
  • -
  • Dired
  • -
  • Evil
  • -
  • Magit
  • -
  • mu4e
  • -
  • org +
  • Edit
  • +
  • Dired
  • +
  • Evil
  • +
  • Magit
  • +
  • mu4e
  • +
  • org
  • -
  • IRC
  • -
  • Languages +
  • IRC
  • +
  • Languages
  • -
  • WoMan
  • -
  • Misc
  • -
  • Credits
  • -
  • License
  • +
  • WoMan
  • +
  • Misc
  • +
  • Credits
  • +
  • License
  • @@ -934,9 +935,216 @@ binding to ,a a function that calls to the proper function.
    -

    Dired

    +

    Edit

    +In this section I define some useful packages for editing. First of all, one of +the coolest packages out there is undo-tree. It allows you to navigate through +the undo history in a tree (because GNU Emacs is cool and keeps track of undo +actions in a tree structure instead of in a stack). This package is included in +recent versions of GNU Emacs. +

    + +
    + +
    (with-eval-after-load 'undo-tree
    +  (global-undo-tree-mode 1)
    +
    +  (setq undo-tree-visualizer-diff t
    +        undo-tree-visualizer-timestamps t
    +        undo-tree-visualizer-relative-timestamps t)
    +
    +  (diminish 'undo-tree-mode)
    +
    +  (with-eval-after-load 'evil-leader
    +    (evil-leader/set-key
    +      "u" 'undo-tree-visualize)))
    +
    +
    + +

    +Another important package is flycheck, which is an on-the-fly syntax checking +extension. This works with lots of languages with proper glue code. +

    + +
    + +
    (use-package let-alist
    +  :ensure t)
    +
    +(use-package flycheck
    +  :ensure t
    +  :diminish
    +  :config
    +  (add-hook 'after-init-hook 'global-flycheck-mode)
    +
    +  ;; Only show the errors buffer if it isn't there and if I'm saving the
    +  ;; buffer.
    +  (setq flycheck-emacs-lisp-load-path 'inherit)
    +  (setq flycheck-check-syntax-automatically '(mode-enabled save))
    +  (setq flycheck-display-errors-function
    +    #'flycheck-display-error-messages-unless-error-list))
    +
    +
    + +

    +A recurring issue in speeches and presentations is that when showing something +with your editor, you have to increase/decrease the fonts. I use the +default-text-scale package for this. +

    + +
    + +
    (use-package default-text-scale
    +  :ensure t
    +  :config
    +  (global-set-key (kbd "C-+") 'default-text-scale-increase)
    +  (global-set-key (kbd "C--") 'default-text-scale-decrease))
    +
    +
    + +

    +Some languages use some delimiters a lot (e.g. lisp languages and +parenthesis). For this reason I'm using the rainbow-delimiters package, which +properly highlights each level in a different way (provided that your theme +supports it). +

    + +
    + +
    (use-package rainbow-delimiters
    +  :ensure t)
    +
    +
    + +

    +I never use the mouse. +

    + +
    + +
    (use-package disable-mouse
    +  :ensure t
    +  :config
    +  (global-disable-mouse-mode)
    +  (setq global-disable-mouse-mode-lighter ""))
    +
    +
    + +

    +Sometimes you begin typing a prefix, but then you forget the following +chord. For this reason which-key was created. It will show the available +commands for the current chord as a list. +

    + +
    + +
    (use-package which-key
    +  :ensure t)
    +
    +
    + +

    +For some modes it is important to count the number of words in the text. For +this, we have wc-mode. +

    + +
    + +
    (use-package wc-mode
    +  :ensure t)
    +
    +
    + +

    +Next on the list, we have writeroom-mode. I honestly don't use this package +that often, but it's cool to have a distraction-free screen from time to time. +

    + +
    + +
    (use-package writeroom-mode
    +  :ensure t)
    +
    +
    + +

    +The expand-region package is an extension that is based on a Vim one, which +expands the region of selection with a single key chord. Even if evil covers +most of my uses, it's convenient to have this tool anyways. +

    + +
    + +
    (use-package expand-region
    +  :ensure t
    +  :config
    +
    +  ; Set C-e as the expand command (mnemonic: expand). This command will
    +  ; supercede the evil binding for "move one line", which I never use anyways.
    +  (global-set-key (kbd "\C-e") 'er/expand-region)
    +  (with-eval-after-load 'evil
    +    (define-key evil-normal-state-map (kbd "\C-e") 'er/expand-region)
    +    (define-key evil-visual-state-map (kbd "\C-e") 'er/expand-region)))
    +
    +(defun er/add-text-mode-expansions ()
    +  "This way we can also expand the region into paragraphs & pages in text mode.
    +Directly taken from: https://github.com/magnars/expand-region.el."
    +
    +  (set (make-local-variable 'er/try-expand-list) (append
    +                                                  er/try-expand-list
    +                                                  '(mark-paragraph
    +                                                    mark-page))))
    +
    +(add-hook 'text-mode-hook 'er/add-text-mode-expansions)
    +
    +
    + +

    +Editing files as root is a bit of a pain because usually the root user doesn't +have the same configuration as the current one, and attempting to do so can be +messy. So, instead of that, we could advice the find-file function so if the +file is not writable by the current user, then GNU Emacs will ask for editing +this same file as root: +

    + +
    + +
    (defadvice find-file (after find-file-sudo activate)
    +  "Find file as root if necessary."
    +  (if (and buffer-file-name
    +           (not (file-writable-p buffer-file-name)))
    +    (if (yes-or-no-p "Do you want to edit this file as root?")
    +        (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))))
    +
    +
    + +

    +YASnippet allows people to define shortcuts for writing some common blocks. +Moreover, it comes with a set of builtin snippets already. Since I don't +remember some of these snippets, I've mapped , h to +yas-describe-tables, which shows the available snippets in another buffer. +

    + +
    + +
    (use-package yasnippet
    +  :ensure t
    +  :diminish yas-minor-mode
    +  :init (yas-global-mode)
    +  :config
    +  (yas-global-mode 1)
    +  (with-eval-after-load 'evil-leader
    +    (evil-leader/set-key "h" 'yas-describe-tables)))
    +
    +
    +
    +
    + +
    +

    Dired

    +
    +

    I use dired mode mainly for attaching document into emails. That being said, whenever I use it, I want basic evil movement.

    @@ -995,9 +1203,9 @@ from the mu4
    -
    -

    Evil

    -
    +
    +

    Evil

    +

    Forgive me, Father, for I have sinned. I've been exposed to modal editing through Vim, and that has changed how I view editing for the foreseeable future. @@ -1205,9 +1413,9 @@ into Evil: C-a for increasing a number, and

    -
    -

    Magit

    -
    +
    +

    Magit

    +

    A git porcelain for GNU Emacs. Even if I'm still using the git CLI, it's certainly useful for some common tasks (I guess that I still need some learning). @@ -1284,9 +1492,9 @@ And repair some key bindings from Evil mode.

    -
    -

    mu4e

    -
    +
    +

    mu4e

    +

    I use mu and mu4e to manage my email. The configuration for this has been taken mainly from the documentation, plus some cool remarks on Reddit. This @@ -1662,9 +1870,9 @@ And finally define a proper shortcut.

    -
    -

    org

    -
    +
    +

    org

    +

    org mode is an incredible tool that keeps me organized: TODOs, notes, agenda, etc. Moreover, it's built in GNU Emacs: @@ -1677,9 +1885,9 @@ etc. Moreover, it's built in GNU Emacs:

    -
    -

    General settings

    -
    +
    +

    General settings

    +

    First of all, let me define some helper functions.

    @@ -1765,9 +1973,9 @@ Where org files reside.
    -
    -

    Publishing

    -
    +
    +

    Publishing

    +

    In order to publish files into HTML, I would like to have htmlize installed. This package allows org to export to HTML in a better way (e.g. allowing code @@ -1799,9 +2007,9 @@ And now let's set all the related settings.

    -
    -

    Agenda

    -
    +
    +

    Agenda

    +

    Custom commands for org-agenda.

    @@ -1902,9 +2110,9 @@ Set up a key binding for org-agenda.
    -
    -

    Capture

    -
    +
    +

    Capture

    +

    Set the default notes file and the key binding.

    @@ -1930,9 +2138,9 @@ And finally set org-capture-templates.
    -
    -

    Other

    -
    +
    +

    Other

    +

    Insert a <kbd></kbd> value in org mode. See this StackExchange answer.

    @@ -1959,24 +2167,24 @@ Insert a <kbd></kbd> value in org mode. See this -

    TODO shortcut for making an org link, and transforming a link into a proper org link

    +
    +

    TODO shortcut for making an org link, and transforming a link into a proper org link

    -
    -

    TODO make it work with evil

    +
    +

    TODO make it work with evil

    -
    -

    TODO Proper keybindings for quick access.

    +
    +

    TODO Proper keybindings for quick access.

    -
    -

    TODO shortcuts for stuff like: create something urgent for today

    +
    +

    TODO shortcuts for stuff like: create something urgent for today

    -
    -

    IRC

    -
    +
    +

    IRC

    +

    I'm giving ERC a chance. First of all, I'm setting up basic stuff.

    @@ -2095,12 +2303,12 @@ And now define a function to connect to both IRC servers.
    -
    -

    Languages

    -
    -
    -

    General

    -
    +
    +

    Languages

    +
    +
    +

    General

    +

    First of all, define a function that identifies some warning keywords (e.g. TODO). This function can then be applied to the proper mode. @@ -2133,9 +2341,9 @@ context too. In this case, I want spell check and wc-mode activated

    -
    -

    Lisp

    -
    +
    +

    Lisp

    +

    Emacs lisp needs rainbow-delimiters, so the amount of parenthesis is less confusing. Moreover, I'm also enabling eldoc-mode and the aforementioned @@ -2156,9 +2364,9 @@ confusing. Moreover, I'm also enabling eldoc-mode and the aforement

    -
    -

    C and C++

    -
    +
    +

    C and C++

    +

    C and C++ only require the warnings-mode-hook function, spell checking for the comments and the usage of tabs instead of spaces. @@ -2182,9 +2390,9 @@ comments and the usage of tabs instead of spaces.

    -
    -

    Ruby

    -
    +
    +

    Ruby

    +

    Include warning keywords in Ruby.

    @@ -2197,9 +2405,9 @@ Include warning keywords in Ruby.
    -
    -

    Go

    -
    +
    +

    Go

    +

    And now my Go configuration. This includes stuff like the usage of goimports, gofmt on save, among many other useful things. @@ -2252,9 +2460,9 @@ And now my Go configuration. This includes stuff like the usage of goimpor

    -
    -

    Tabs vs spaces

    -
    +
    +

    Tabs vs spaces

    +

    Tabs or spaces? Both. The smart-tabs-mode has the philosophy of: tabs for indentation, spaces for alignment. This is only applied in languages where I'm @@ -2275,9 +2483,9 @@ usings tabs for indentation (C, C++ and Go).

    -
    -

    Inferior markup languages.

    -
    +
    +

    Inferior markup languages.

    +
    ;; Markdown mode with preview mode in the browser.
    @@ -2308,9 +2516,9 @@ usings tabs for indentation (C, C++ and Go).
     
    -
    -

    Web-related stuff.

    -
    +
    +

    Web-related stuff.

    +

    Slim and SCSS.

    @@ -2395,9 +2603,9 @@ can be frustrating without proper formatting.
    -
    -

    Others

    -
    +
    +

    Others

    +

    CMake for y'all.

    @@ -2470,9 +2678,9 @@ criteria really).
    -
    -

    WoMan

    -
    +
    +

    WoMan

    +

    WoMan is a package that is included inside of GNU Emacs by default, and that takes care of visualizing man pages. Let's properly setup Evil mode for this: @@ -2505,9 +2713,9 @@ Finally, I want man pages to fill all the frame:

    -