Files
dot-emacs/emacs.html

10429 lines
513 KiB
HTML
Raw Permalink Normal View History

2017-06-17 18:58:04 +02:00
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
2021-05-01 13:15:16 +02:00
<!-- 2021-05-01 Sa 13:15 -->
2017-06-17 18:58:04 +02:00
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<meta name="generator" content="Org mode" />
2017-09-01 07:51:06 +02:00
<meta name="author" content="Tom" />
2017-06-17 18:58:04 +02:00
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
2017-09-01 07:51:06 +02:00
Copyright (C) 2012-2013 Free Software Foundation, Inc.
2017-06-17 18:58:04 +02:00
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
2020-09-02 20:44:21 +02:00
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#orgca23a83">1. Introduction</a></li>
<li><a href="#org12b67c5">2. Config Log, Trivia, Notes, Changes</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org175b172">2.1. Changelog</a></li>
<li><a href="#orgd980427">2.2. <span class="todo TODO">TODO</span> </a></li>
<li><a href="#org9e19170">2.3. Parking Lot / Snippets</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#orgc7e0259">2.3.1. buffer-local hook</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org38567ce">2.4. .emacs config version</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org03939f5">3. System Specifics</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#orgd6226f1">3.1. Global init file+dir vars, portable</a></li>
<li><a href="#orge74e7c4">3.2. Shortcut Mode - mode specific help about my own customizations</a></li>
<li><a href="#org491fc9b">3.3. Fontlock-mode - use syntax highlighting on graphical displays</a></li>
<li><a href="#org1fc5603">3.4. line-cursor in console</a></li>
<li><a href="#org5145e0b">3.5. Backup Config</a></li>
<li><a href="#org7771b39">3.6. console backspace fix</a></li>
<li><a href="#org2ec7557">3.7. hide menu- and tool-bar</a></li>
<li><a href="#orgcb01af2">3.8. stay silent on startup</a></li>
<li><a href="#org858e9d5">3.9. y means yes</a></li>
<li><a href="#org2f41c16">3.10. show col in modeline</a></li>
<li><a href="#orgf9b1aba">3.11. file or buffer in title</a></li>
<li><a href="#org9aff8c5">3.12. avoid invalid files</a></li>
<li><a href="#orga4aa3c4">3.13. prepare load-path</a></li>
<li><a href="#orgb10a9bf">3.14. Hydra</a></li>
<li><a href="#orgc67eaac">3.15. byte-compile all of them, if needed</a></li>
<li><a href="#org970a297">3.16. increase fontsize with ctrl-+ and ctrl--</a></li>
<li><a href="#orgcaa0c3d">3.17. WINDOW management stuff</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org28deae0">3.17.1. resize windows by keyboard</a></li>
<li><a href="#org7d74ca0">3.17.2. switch windows with MS-WINDOWS key</a></li>
<li><a href="#org263bafa">3.17.3. M-o switch window or buffer</a></li>
<li><a href="#org904b6eb">3.17.4. Split window to 4 parts</a></li>
<li><a href="#orgbc09849">3.17.5. Remember and Restore Window Configurations - winner mode</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org8572ada">3.18. re-read a modified buffer</a></li>
<li><a href="#orgb9a20d8">3.19. global TAB/Indent config</a></li>
<li><a href="#org1db95c4">3.20. handy aliases</a></li>
<li><a href="#org7b30850">3.21. various settings</a></li>
<li><a href="#orge52ff88">3.22. load imenu</a></li>
<li><a href="#orgcc5be60">3.23. copy/paste Config</a></li>
<li><a href="#org348d202">3.24. use more mem</a></li>
<li><a href="#org21d9b27">3.25. better file name completion</a></li>
<li><a href="#org5a8ed25">3.26. abbreviations</a></li>
<li><a href="#org94f48b8">3.27. meaningful names for buffers with the same name</a></li>
<li><a href="#orgb4209ae">3.28. packages</a></li>
<li><a href="#org6ac81b9">3.29. My own global variables</a></li>
<li><a href="#orgbbee73a">3.30. More scratch space</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#orgfd88c99">3.30.1. Text scratch</a></li>
<li><a href="#org78a10be">3.30.2. Autoscratch</a></li>
<li><a href="#org54bbb5a">3.30.3. Persistent Scratch</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org0a83d1e">3.31. Recenter config</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#orga208ea6">4. Global Key Bindings</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org9f5d04c">4.1. c-h != delete</a></li>
<li><a href="#org01c8ac1">4.2. general keys (re-)mappings</a></li>
<li><a href="#orgf836054">4.3. display a list of my own global key bindings and aliases</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org1c11627">5. Productivity Functions</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#orgb2f7324">5.1. goto line with tmp line numbers</a></li>
<li><a href="#org50ef33c">5.2. invert fore- and background</a></li>
<li><a href="#org666e00e">5.3. Some useful bindings for Home and End keys Hit the key once to</a></li>
<li><a href="#orgbdb3ebb">5.4. percent function</a></li>
<li><a href="#org73d1e03">5.5. Simulate vi's % (percent) function</a></li>
<li><a href="#orgee4bdea">5.6. Move region</a></li>
<li><a href="#org1ed413d">5.7. comment-uncomment region with one key binding</a></li>
<li><a href="#orga2c274a">5.8. search for symbol at point</a></li>
<li><a href="#orgebf7f5e">5.9. Window Margin</a></li>
<li><a href="#orgd9b8ff4">5.10. Fill and justify a paragraph</a></li>
<li><a href="#orgb03f9b1">5.11. Make a read-only copy of the current buffer</a></li>
<li><a href="#orge44c137">5.12. Cleanup, close all windows and kill all buffers</a></li>
<li><a href="#orgfb95865">5.13. Cleanup current buffer</a></li>
<li><a href="#orgf784ada">5.14. Remove Umlauts and other crab in current buffer</a></li>
<li><a href="#org6f08c2c">5.15. Better newline(s)</a></li>
<li><a href="#org40f3b88">5.16. Mouse Rectangle</a></li>
<li><a href="#org05fe262">5.17. DOS &lt;=&gt; UNIX conversion helpers</a></li>
<li><a href="#org1d2a610">5.18. helper do add the same thing to multiple mode hooks</a></li>
<li><a href="#org716474f">5.19. helper to catch load errors</a></li>
<li><a href="#org01e1bd9">5.20. Alignment Wrappers</a></li>
<li><a href="#org381ada7">5.21. String Helpers</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#orgeef6f86">6. Modes</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org4d87610">6.1. Programming Languages</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org4c00242">6.1.1. VALA</a></li>
<li><a href="#orgc2c31d3">6.1.2. rust mode</a></li>
<li><a href="#orgaad8f72">6.1.3. python mode</a></li>
<li><a href="#org586f030">6.1.4. Shell-Script Mode</a></li>
<li><a href="#org42adf73">6.1.5. cperl mode</a></li>
<li><a href="#org3bbbe92">6.1.6. Paredit for lisp only</a></li>
<li><a href="#org5daac4e">6.1.7. Smart Parens</a></li>
<li><a href="#org793f9f5">6.1.8. ETAGS</a></li>
<li><a href="#org399565c">6.1.9. Go Lang</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org7f68b34">6.2. Text Modes</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org87df60f">6.2.1. sgml</a></li>
<li><a href="#orgd81b540">6.2.2. web-mode (JS, HTML, CSS combined)</a></li>
<li><a href="#orgdd5daf7">6.2.3. Cisco Mode</a></li>
<li><a href="#orgfa4df1a">6.2.4. Markdown</a></li>
<li><a href="#orgabc03ca">6.2.5. POD mode</a></li>
<li><a href="#org21f980b">6.2.6. conf-mode</a></li>
<li><a href="#orgb1c7026">6.2.7. Config::General mode</a></li>
<li><a href="#orgb61f2e1">6.2.8. Xmodmap Mode</a></li>
<li><a href="#org6f66f7d">6.2.9. MMM Mode</a></li>
<li><a href="#orgbf828c3">6.2.10. Yaml Mode</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org36b1524">6.3. Text Manupilation</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org37f300e">6.3.1. expand-region</a></li>
<li><a href="#orge98b15d">6.3.2. Mark, Copy, Yank Things</a></li>
<li><a href="#org1e99d01">6.3.3. change-inner</a></li>
<li><a href="#orga0d03c2">6.3.4. Rotate text</a></li>
<li><a href="#org8cb32f9">6.3.5. Word wrapping</a></li>
<li><a href="#orgd5bbf4a">6.3.6. Viking Mode</a></li>
<li><a href="#org2f83c5d">6.3.7. HTMLize</a></li>
<li><a href="#org7ebf55c">6.3.8. iEdit (inline edit multiple searches)</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#orgdac7240">6.4. Interactives</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org1d14a75">6.4.1. eShell stuff, or if interactive stuff is needed, use ansi-term</a></li>
<li><a href="#org595dd72">6.4.2. Emacs LISP interactive</a></li>
<li><a href="#orgdfa3a7c">6.4.3. el2markdown</a></li>
<li><a href="#orgcca9912">6.4.4. tramp mode</a></li>
<li><a href="#org264e425">6.4.5. org mode</a></li>
<li><a href="#org3308fc0">6.4.6. org agenda mode</a></li>
<li><a href="#org182c38f">6.4.7. org table mode</a></li>
<li><a href="#orgb4fd415">6.4.8. org mode slideshows</a></li>
<li><a href="#org0dd6e1f">6.4.9. outshine mode</a></li>
<li><a href="#orgaacc093">6.4.10. outline mode</a></li>
<li><a href="#org9cce2a1">6.4.11. narrowing (no mode but fits here)</a></li>
<li><a href="#orgef20fc9">6.4.12. ANSI-TERM (inferior shells/interpreters and REPLs)</a></li>
<li><a href="#org4d46d6e">6.4.13. Puppet</a></li>
<li><a href="#org13759ae">6.4.14. Novel Mode - Screen Reader</a></li>
<li><a href="#orgc06e29d">6.4.15. Macro Math</a></li>
<li><a href="#orgc7adbb3">6.4.16. Common-Lisp (SLIME)</a></li>
<li><a href="#org8694a3b">6.4.17. INFO Mode</a></li>
<li><a href="#org05009ac">6.4.18. calc et al.</a></li>
<li><a href="#org5e61a75">6.4.19. MACROs</a></li>
<li><a href="#org6ce8c6d">6.4.20. EWW browser stuff</a></li>
<li><a href="#org3769139">6.4.21. Firestarter</a></li>
<li><a href="#orgf7b647a">6.4.22. Tabulated List Mode</a></li>
<li><a href="#org415695d">6.4.23. Help Mode</a></li>
<li><a href="#org095cda7">6.4.24. Suggest Mode</a></li>
<li><a href="#orgd744fec">6.4.25. Followcursor Mode</a></li>
<li><a href="#org98a039d">6.4.26. RCS Mode</a></li>
<li><a href="#orgeef2915">6.4.27. Magit</a></li>
<li><a href="#orga69858c">6.4.28. Dired</a></li>
<li><a href="#org29a5953">6.4.29. Ediff Config</a></li>
<li><a href="#org6dc9a1f">6.4.30. Smerge Config</a></li>
<li><a href="#orgcc90b8a">6.4.31. Projectile</a></li>
<li><a href="#org41fb6c7">6.4.32. Occur</a></li>
<li><a href="#org977f4e2">6.4.33. Window Hydra</a></li>
<li><a href="#orgcb8f76f">6.4.34. Eyebrowse Workspaces</a></li>
<li><a href="#orgf0465a8">6.4.35. Highlighting Indentation</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org0dd293d">6.5. Emacs Interface</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#org5b2ea16">6.5.1. Parens</a></li>
<li><a href="#orgf012fe3">6.5.2. highlight todo keywords (such as <i>FIXME</i>)</a></li>
<li><a href="#org0b7cdde">6.5.3. UNDO Tree Mode</a></li>
<li><a href="#orgfebbe55">6.5.4. Smarter M-x Mode (smex)</a></li>
<li><a href="#org593e3c6">6.5.5. Smarter Search</a></li>
<li><a href="#org43ae527">6.5.6. Which Func</a></li>
<li><a href="#org46c1a5e">6.5.7. Show current-line in the Fringe</a></li>
<li><a href="#org3d68b6b">6.5.8. Recent Files</a></li>
<li><a href="#org238949b">6.5.9. IDO mode</a></li>
<li><a href="#org5b9a705">6.5.10. Save cursor position</a></li>
<li><a href="#org84a70ae">6.5.11. DoReMi experimentation</a></li>
<li><a href="#orge147b38">6.5.12. Hightligt TABs</a></li>
<li><a href="#orgc172036">6.5.13. Browse kill-ring</a></li>
<li><a href="#org9f7792a">6.5.14. goto-last-change</a></li>
<li><a href="#org8ec5a23">6.5.15. Bookmarks</a></li>
<li><a href="#org43c0494">6.5.16. which-key</a></li>
<li><a href="#org97d098a">6.5.17. iBuffer mode</a></li>
<li><a href="#org19822ef">6.5.18. Printing</a></li>
<li><a href="#orga40232d">6.5.19. Beacon mode (pointer blink)</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#orgfbd2d87">6.6. mode-line setup (must be the last mode)</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
2021-05-01 13:15:16 +02:00
<li><a href="#org91a9200">7. Emacs Autoconfig / Customize group / final stuff</a>
2020-09-02 20:44:21 +02:00
<ul>
2021-05-01 13:15:16 +02:00
<li><a href="#orge918444">7.1. font faces</a></li>
<li><a href="#org0e03ca5">7.2. emacs server</a></li>
<li><a href="#org0a9ba17">7.3. variables</a></li>
<li><a href="#org669ec72">7.4. done</a></li>
2020-09-02 20:44:21 +02:00
</ul>
</li>
</ul>
</div>
</div>
<p>
2021-05-01 13:15:16 +02:00
Toms Emacs Config - portable - version ("20210501.01") -*-emacs-lisp-*-
2020-09-02 20:44:21 +02:00
</p>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgca23a83" class="outline-2">
<h2 id="orgca23a83"><span class="section-number-2">1</span> Introduction</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-1">
<p>
This is my emacs config, it is more than twenty years old. It
mostly contains stuff implemented by myself, but there are also
snippets I found here and there. The config will probably not be
usefull for anyone else but myself.
</p>
<p>
If you're reading the html exported version: be advised, that I do
NOT maintain my emacs config with "literate programming". Instead I
maintain a plain old .emacs file, which I use at home and work, on
windows, linux and freebsd, console or X11. I use outshine minor
mode to organize my config and I use outorg to export it to org
mode and from there to html.
</p>
<p>
Also I don't use any packaging mechanism, instead I download all
the required elisp files manually and update them only if
required. There's a melpa config toggle though, which I only use to
try out new modes. I distribute my .emacs config along with the
lisp directory to all systems where I need it using a Makefile and
scp. The reason is that I work on a couple of systems without
direct internet access, where packaging or git don't work. So, I
don't use these things nowhere. It's ok for me, I'm used to it.
</p>
<p>
Another thing you might wonder about are my key bindings or
(sometimes) the lack thereof. My problem with key bindings is that
I don't have any useful prefixes left. I am using ONLY commandline
tools, my window manager is Xmonad, I use screen, bash and
mutt. The only applications where I use the mouse is firefox and
gimp. So, it is very hard to avoid conflicts AND memoize new key
bindings. Some key bindings are so deeply wired into muscle memory
that I could use them while drunk or dying.
</p>
<p>
Therefore I use lots of aliases in emacs for not-so-regular used
functions, which turned out to be sometimes easier to type than an
actual key binding.
</p>
<p>
The html export has been created with the function
outshine-to-html, written by myself, see below.
</p>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org12b67c5" class="outline-2">
<h2 id="org12b67c5"><span class="section-number-2">2</span> Config Log, Trivia, Notes, Changes</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-2">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org175b172" class="outline-3">
<h3 id="org175b172"><span class="section-number-3">2.1</span> Changelog</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-2-1">
<p>
20160420.03:
</p>
<ul class="org-ul">
<li>started with Changelog and outshine mode</li>
<li>fixed tabs</li>
<li>reorganized keys</li>
<li>added new goto line func</li>
</ul>
<p>
20160421.01:
</p>
<ul class="org-ul">
<li>added smex</li>
<li>added show-keys()</li>
<li>added redo</li>
<li>ssh et. al. interactive in eshell</li>
<li>added recompile()</li>
</ul>
<p>
20160421.02:
</p>
<ul class="org-ul">
<li>added dividers</li>
<li>using org headers</li>
<li>better show-keys()</li>
</ul>
<p>
20160421.03:
</p>
<ul class="org-ul">
<li>added windows support</li>
</ul>
<p>
20160421.04:
</p>
<ul class="org-ul">
<li>added elisp repl support</li>
</ul>
<p>
20160424.01:
</p>
<ul class="org-ul">
<li>added custom modeline</li>
<li>added which-func-mode</li>
<li>shortened some major mode names</li>
<li>added diminish for shorter minor mode names</li>
<li>added better printing menu</li>
</ul>
<p>
20160425.01:
</p>
<ul class="org-ul">
<li>fixed ielm integration</li>
<li>C-x e = eval (buffer|region)</li>
<li>C-x C-e = send (buffer|region) to ielm and eval there</li>
</ul>
<p>
20160425.02:
</p>
<ul class="org-ul">
<li>fix word wrapping</li>
</ul>
<p>
20160426.01:
</p>
<ul class="org-ul">
<li>fixed mode-line config 4 win emacs</li>
<li>added M-&lt;up|down&gt; move-region</li>
</ul>
<p>
20160426.01:
</p>
<ul class="org-ul">
<li>added markdown</li>
</ul>
<p>
20160427.01+02:
</p>
<ul class="org-ul">
<li>cosmetics</li>
</ul>
<p>
20160428.01:
</p>
<ul class="org-ul">
<li>fringe cursor</li>
</ul>
<p>
20160429.01:
</p>
<ul class="org-ul">
<li>file name completion</li>
<li>C-# finally, search for symbol at point</li>
<li>C-c C-c now comments or uncomments regios or line, whatever is current</li>
</ul>
<p>
20160501.01:
</p>
<ul class="org-ul">
<li>no outshine minor in python</li>
<li>added recent files support</li>
</ul>
<p>
20160501.02:
</p>
<ul class="org-ul">
<li>added margin() function, no key binding though</li>
</ul>
<p>
20160503.01:
</p>
<ul class="org-ul">
<li>added C-q fill+justify paragraph macro</li>
<li>added alias 'i' for info manuals</li>
</ul>
<p>
20160503.02:
</p>
<ul class="org-ul">
<li>added 'cp to create read-only buffer copy</li>
</ul>
<p>
20160504.01:
</p>
<ul class="org-ul">
<li>better fringe, now also inversed with C-c i</li>
</ul>
<p>
20160505.01:
</p>
<ul class="org-ul">
<li>added electric-align mode</li>
<li>better outline header colors</li>
<li>no more line numbers in sk occur buffer</li>
</ul>
<p>
20160507.01:
</p>
<ul class="org-ul">
<li>disable electric-align-momde (broken), using M-x align instead</li>
<li>hightlighting TABs with extra font</li>
</ul>
<p>
20160509.01:
</p>
<ul class="org-ul">
<li>fixed margin()</li>
<li>discovered that C-x 0 deletes current window, god did I miss this one!</li>
</ul>
<p>
20160510.01:
</p>
<ul class="org-ul">
<li>added kill-all-buffers()</li>
</ul>
<p>
20160510.02:
</p>
<ul class="org-ul">
<li>no more load-file</li>
<li>added C-c [wlpa]: easy copy things at point
without marking them</li>
</ul>
<p>
20160511.01:
</p>
<ul class="org-ul">
<li>better buffer names with uniquify</li>
</ul>
<p>
20160511.02:
</p>
<ul class="org-ul">
<li>copy-* functions now blink region</li>
<li>added del-* functions, bound to C-d:
press multiple times to delete word, line, paragraph, buffer</li>
</ul>
<p>
20160513.01:
</p>
<ul class="org-ul">
<li>fixed END key func</li>
</ul>
<p>
20160516.01:
</p>
<ul class="org-ul">
<li>removed C-d stuff, replaced with vikiing-mode</li>
</ul>
<p>
20160517.01:
</p>
<ul class="org-ul">
<li>changed highlight face</li>
<li>enabled debug-on-error in lispmode</li>
<li>enabled IDO mode globally, I just tend to love love love it</li>
</ul>
<p>
20160517.02:
</p>
<ul class="org-ul">
<li>added workgroup.el, started experimenting</li>
<li>enabled Super<sub>L</sub> (for workgroups)</li>
</ul>
<p>
20160519.01:
</p>
<ul class="org-ul">
<li>fixed write-file, now ido mode is disabled for this one.</li>
</ul>
<p>
20160520.01:
</p>
<ul class="org-ul">
<li>no x-sel on windows (C-v+C-c =&gt; emacs doesn't work anymore otherwise)</li>
<li>added eldoc mode to elisp hook</li>
</ul>
<p>
20160520.02:
</p>
<ul class="org-ul">
<li>added novel-mode, for better reading</li>
</ul>
<p>
20160522.01:
</p>
<ul class="org-ul">
<li>added vi's % jump paren emulation</li>
<li>enhanced novel-mode</li>
<li>enabled save-place mode which is VERY useful in combination with
novel-mode</li>
</ul>
<p>
20160523.01:
</p>
<ul class="org-ul">
<li>detached novel-mode into its own module, maintain on github
enabled with C-n</li>
</ul>
<p>
20160526.01:
</p>
<ul class="org-ul">
<li>added toggle-melpa</li>
</ul>
<p>
20160527.01:
</p>
<ul class="org-ul">
<li>added htmlize</li>
</ul>
<p>
20160529.01:
</p>
<ul class="org-ul">
<li>added html-listify</li>
</ul>
<p>
20160530.01:
</p>
<ul class="org-ul">
<li>added key chords</li>
<li>added open-line-above+below</li>
</ul>
<p>
20160602.01:
</p>
<ul class="org-ul">
<li>C-q now fills and pressing it again un-fills</li>
</ul>
<p>
20160606.01:
</p>
<ul class="org-ul">
<li>deactivated key-chords, I didn't use them and they were annoying.</li>
</ul>
<p>
20160609.01:
</p>
<ul class="org-ul">
<li>added puppet mode</li>
</ul>
<p>
20160614.01:
</p>
<ul class="org-ul">
<li>added rotate-text (C-t)</li>
<li>added macro math (C-x-0) (0 used as =)</li>
</ul>
<p>
20160713.01:
</p>
<ul class="org-ul">
<li>fixed indent for Makefiles</li>
</ul>
<p>
20160729.01:
</p>
<ul class="org-ul">
<li>rm duplicate abbr defs</li>
</ul>
<p>
20160916.01:
</p>
<ul class="org-ul">
<li>enable mouse mark to copy</li>
</ul>
<p>
20160926.01:
</p>
<ul class="org-ul">
<li>Dont kill-buffer, kill-this-buffer instead</li>
</ul>
<p>
20160928.01:
</p>
<ul class="org-ul">
<li>change macro math C-x 0 to C-x C-0 so that C-0 is
usable again for close window</li>
<li>elisp mode: debug-on-error only on non-cygwin</li>
</ul>
<p>
20161011.01:
</p>
<ul class="org-ul">
<li>added dos2unix and unix2dos</li>
</ul>
<p>
20161014.01:
</p>
<ul class="org-ul">
<li>fix auto-indent in conf-mode</li>
<li>force C-c C-c comment-uncomment in conf-mode</li>
</ul>
<p>
20161018.01:
</p>
<ul class="org-ul">
<li>more effective conf-mode disarming (own defun)</li>
</ul>
<p>
20161022.01:
</p>
<ul class="org-ul">
<li>better paren mode</li>
</ul>
<p>
20161024.01:
</p>
<ul class="org-ul">
<li>fixed org mode hook</li>
</ul>
<p>
20161027.01:
</p>
<ul class="org-ul">
<li>turn off tramp stuff in kill-all-buffers as well,
so that after executing it, no more ssh prompt
appears on C-x f.</li>
</ul>
<p>
20161106.01:
</p>
<ul class="org-ul">
<li>added iedit mode with C-c e</li>
<li>added file-open support to eshell (aliases: vi + emacs)</li>
<li>much better C-l behavior in eshell (eshell/clear)</li>
</ul>
<p>
20161205.01:
</p>
<ul class="org-ul">
<li>added SLIME, sbcl and paredit support, only loaded when exists</li>
</ul>
<p>
20161206.01:
</p>
<ul class="org-ul">
<li>elisp mode: debug-on-error finally completeley disabled</li>
<li>added alias 'table, which enables org-mode table support everywhere</li>
</ul>
<p>
20170205.01:
</p>
<ul class="org-ul">
<li>started with ETAGS support</li>
</ul>
<p>
20170212.01:
</p>
<ul class="org-ul">
<li>added copy-defun (C-c f) to copy whole functions as is</li>
</ul>
<p>
20170212.02:
</p>
<ul class="org-ul">
<li>now using € (alt-r + e) as jump to etag</li>
</ul>
<p>
20170215.02:
</p>
<ul class="org-ul">
<li>added goto-last-change (C-b)</li>
<li>+test section</li>
<li>paredit</li>
</ul>
<p>
20170215.02:
</p>
<ul class="org-ul">
<li>disabled workgoups mode, don't use it, doesn't load correctly</li>
<li>fixed windows switch, no more printing popup on startup</li>
</ul>
<p>
20170220.01:
</p>
<ul class="org-ul">
<li>finally disabled aggressive-indent, it annoys more than it helps</li>
<li>added some bookmark aliases (bm, to, bl, like apparix)</li>
<li>added C-c y [..] copy+yank functions so that I can copy and paste
stuff very fast with one key commbo, like yy in vi.</li>
<li>added copy-parens, copy-quote, copy-help (help message)</li>
</ul>
<p>
20170220.02:
</p>
<ul class="org-ul">
<li>fixed C-c y y: indent correctly</li>
</ul>
<p>
20170220.03:
</p>
<ul class="org-ul">
<li>fixed C-y+mouse-2: both use primary selection</li>
</ul>
<p>
20170221.01:
</p>
<ul class="org-ul">
<li>added which-key</li>
</ul>
<p>
20170223.01:
</p>
<ul class="org-ul">
<li>org-mode enhancements, C-n capture from everywhere</li>
<li>fixed org-mode todo keywords</li>
<li>fixed duplicate yank on win32 on mouse2</li>
</ul>
<p>
20170223.01:
</p>
<ul class="org-ul">
<li>forgot to mv novel-mode to C-c C-n</li>
<li>better org heading faces</li>
</ul>
<p>
20170224.01:
</p>
<ul class="org-ul">
<li>finally fixed C-t, now works everywhere</li>
<li>added more org short commands</li>
</ul>
<p>
20170224.02:
</p>
<ul class="org-ul">
<li>fixed org-mode M-return</li>
<li>added support for windmove (WINDOWS-Key+Arrow: switch window)</li>
</ul>
<p>
20170224.03:
</p>
<ul class="org-ul">
<li>better org colours</li>
</ul>
<p>
20170224.03:
</p>
<ul class="org-ul">
<li>better org capture tpl (DRAFT)</li>
<li>capturing works now globally, even if no org file is open</li>
<li>using org-indent 4</li>
</ul>
<p>
20170224.05:
</p>
<ul class="org-ul">
<li>fixed org tpls</li>
</ul>
<p>
20170227.01:
</p>
<ul class="org-ul">
<li>fix cut/paste org subtress</li>
<li>M-o now switch buffer if 1 window, else switch window</li>
</ul>
<p>
20170227.02:
</p>
<ul class="org-ul">
<li>added alias 'dp which displays everything
there is to know about point (like current face, mode, etc)</li>
</ul>
<p>
20170228.01:
</p>
<ul class="org-ul">
<li>org-refile now works recursivly with completion</li>
<li>org-refile also now uses ido-mode and completes in minibuffer</li>
<li>added alias '2table which converts CSV region to table</li>
<li>added shortcut formatting defuns 'bold, 'italic, 'underline and 'code
which call 'org-emphasize respectively on current region,
including key bindings with org mode keymap (C-c b,/,c,_)</li>
<li>hide emphasized markers in org mode</li>
<li>renamed 'recompile to 'recompile-el and fixed it</li>
<li>added 'info-find-file</li>
</ul>
<p>
20170301.01:
</p>
<ul class="org-ul">
<li>added 'tvd-org-left-or-level-up bound to &lt;C-left&gt; in org mode</li>
<li>&lt;C-up|down&gt; in org mode now jump up on current level and
fold current one and unfolds the target heading</li>
<li>enabled org-bullets</li>
<li>customized height of org-level faces</li>
</ul>
<p>
20170301.02:
</p>
<ul class="org-ul">
<li>org mode emphasize shortcuts (C-c b&#x2026;) expand region if
theres no region active.</li>
</ul>
<p>
20170301.03:
</p>
<ul class="org-ul">
<li>dis line num in org (faster)</li>
</ul>
<p>
20170303.01:
</p>
<ul class="org-ul">
<li>elmacro support added, incl fix for org and outshine,
F6 starts (or stops) a macro and displays the generated
defun. CTRL-F6 executes the last macro interactively,
&lt;ret&gt; repeats, a repeats til EOF, q aborts, e enter macro
(with completion)</li>
<li>C-x C-s on * elmacro &#x2026; * buffer stores it to tvd-macro-file</li>
</ul>
<p>
20170305.01:
</p>
<ul class="org-ul">
<li>added elmacro defadvice, run after done with macro, it will
be evaluated and saved along with a repeater defun.</li>
<li>display red [REC] hint on the mode-line while recording</li>
<li>added ~ shortcut for use inside IDO so I can reach $HOME
very fast from everywhere, no more editing pre-filled
current path and entering <i>home/$user</i>. Yeah!</li>
<li>added flip-window (bound to M-O (ALT-shift-o)</li>
<li>added cleanup-buffer (alias cb)</li>
<li>fixed C-&lt;ret&gt; and C-S-&lt;ret&gt;</li>
</ul>
<p>
20170306.01:
</p>
<ul class="org-ul">
<li>re-enabled linenum mode</li>
<li>fixed custom modeline</li>
</ul>
<p>
20170306.01:
</p>
<ul class="org-ul">
<li>which-func not in elisp anymore</li>
<li>added alias 'ee for 'eval-expression</li>
<li>added 'sa (show-aliases)</li>
<li>some occur enhancements for 'sk and 'sa.</li>
<li>note: inside <b>Occur</b>: q:quit, g:reload, e:edit (buffer must be open)</li>
</ul>
<p>
20170307.01:
</p>
<ul class="org-ul">
<li>fixed 'sk and 'sa</li>
<li>added key bindings to mark things. M-a is the prefix, followed by:
a - all, p - paragraph, f - function, l - line, w - word.</li>
<li>disabled M-O (flip-windows) on console emacs</li>
</ul>
<p>
20170309.01:
</p>
<ul class="org-ul">
<li>added C-c s,u,e and M-a s,u,e</li>
</ul>
<p>
20170309.02:
</p>
<ul class="org-ul">
<li>re-enabled paredit, its better in ielm and slime</li>
<li>added alias 'pe to quickly enable/disable par-edit</li>
<li>added virtual eShell dev /dev/log which stores stuff in <b>LOG</b></li>
</ul>
<p>
20170313.01:
</p>
<ul class="org-ul">
<li>iedit to C-c C-e, so C-c e works again (copy email)</li>
<li>put eshell aliases into .emacs(here) no need for aliases file anymore</li>
<li>added copy-comment (C-c c), copy-and-yank-comment (C-c y c) and
m-mark-comment (M-a c)</li>
</ul>
<p>
20170314.01:
</p>
<ul class="org-ul">
<li>enhanced copy-comment (that is, rewrote it), it now supports
indented multiline comments</li>
</ul>
<p>
20170315.01:
</p>
<ul class="org-ul">
<li>fixed C-c y [cpwf]</li>
<li>fixed copy[+yank+mark] word, it now includes - _ .</li>
<li>added copy-ip (C-c i), yank-ip (C-c y i) and mark-ip (M-a i)</li>
<li>copy-url alternatively copies file-path if it's no url at point</li>
<li>added numerical arg support to yy</li>
</ul>
<p>
20170321.01:
</p>
<ul class="org-ul">
<li>rewrote copy-comment stuff, now supports blocks of comment
after code etc.</li>
</ul>
<p>
20170323.01:
</p>
<ul class="org-ul">
<li>moved the mark,copy,yank stuff into its own mode</li>
</ul>
<p>
20170327.01:
</p>
<ul class="org-ul">
<li>added defadvice for mcyt mode, so that I can use C-v to
always yank the last thing copied.</li>
</ul>
<p>
20170502.01:
</p>
<ul class="org-ul">
<li>added config for ibuffer</li>
</ul>
<p>
20170503.01:
</p>
<ul class="org-ul">
<li>added ibuffer-vc support</li>
</ul>
<p>
20170503.02:
</p>
<ul class="org-ul">
<li>added ibuffer-tramp support</li>
<li>disabled ibuffer tab-collaps stuff</li>
</ul>
<p>
20170505.01:
</p>
<ul class="org-ul">
<li>generalized init-dir+file variables, now more portable, i hope</li>
</ul>
<p>
20170508.01:
</p>
<ul class="org-ul">
<li>backup tramp files remote</li>
<li>do not backup emacs state files</li>
</ul>
<p>
20170509.01:
</p>
<ul class="org-ul">
<li>version fix</li>
</ul>
<p>
20170523.01:
</p>
<ul class="org-ul">
<li>commented ssh backup stuff, not working yet, destroys tramp</li>
<li>added inferior shells for perl, ruby and python (iperl, iruby, ipython)
with ansi-term</li>
</ul>
<p>
20170610.01:
</p>
<ul class="org-ul">
<li>org mode: added C-c C-# to edit src blocks in an extra window</li>
<li>org mode: &lt;ret&gt; opens link in eww</li>
<li>ido-find-file advice: if not writable, try sudo/tramp</li>
<li>+eshell-there remote eshell (Alias: et)</li>
<li>disabled pager in eshell</li>
<li>fixed eshell/x, now uses C-d</li>
<li>org mode: DONE makes heading greyish</li>
<li>re-organized emacs config, now with subsections</li>
<li>removed lisp electric return, destroyed almost all modes</li>
<li>added POD mode with specific abbrevs and including specific outlining</li>
<li>added heading cycle code for outline mode as well</li>
<li>added outline 'n (narrow) + 'w (widen)</li>
<li>added orange fringe for narrowing (org, outline and everywhere else</li>
<li>added alias 'colors</li>
<li>added 'dl (aka describe-library to display the doc string in
COMMENTARY section of .el files</li>
<li>added "C-c t" to copy an org mode cell</li>
<li>ena org pretty entities, list: org-entities-help</li>
<li>2table =&gt; tablify, which is now a function and uses region or whole buffer</li>
<li>added indirect narrowing buffers</li>
<li>renamed all occurences of my- to tvd- so I better know which stuff is mine</li>
<li>added table-to-* org table exporters with aliases</li>
<li>inside org mode: C-c o copy table c[o]lumn, C-c t copy [t]able cell</li>
<li>experimental: added beacon mode (blinking pointer)
(moved 'seq from exp. elpa to lisp/)</li>
<li>added render-html to render current html buffer with eww</li>
<li>added align-regexp-repeat[-left|right] wrappers</li>
<li>fixed org mode C-&lt;down|up&gt; jump paragraphs if not on heading</li>
<li>added 'tvd-outshine-jump (alias 'j) to directly jump to headers
with IDO completion and as sparse-tree, very cool!
mapped to C-c C-j</li>
<li>added <b>text</b> scratch buffer with text mode</li>
<li>added jump-paren-match-or-insert-percent, bound to %, which jumps parens
or inserts a % if not on a paren. Better than C-5, haha.</li>
<li>added 'ffxs</li>
<li>added emacs-change-log</li>
<li>removed GNUS config, not used anymore</li>
<li>restored C-d binding to viking in paredit</li>
<li>added outshine HTML exporter via org: outshine-to-html</li>
<li>fixed outshine config</li>
<li>added (my) config-general-mode</li>
<li>fixed pod format inserters</li>
</ul>
<p>
20170629.01:
</p>
<ul class="org-ul">
<li>added tablist-minor-mode (+config)</li>
<li>added config for tabulated-list-mode</li>
<li>added config for help-mode</li>
<li>added default filename for outshine-to-html</li>
<li>Info mode: C-left+C-right history keys</li>
<li>added loader for el2markdown</li>
<li>removed smart-forward, it annoys me</li>
<li>made tvd-outshine-jump more portable, do not use hardcoded
regexps anymore, use outshine functions</li>
<li>added 'change-inner and ci simulators'</li>
<li>added suggest.el with my own reload function</li>
<li>modified recentf: do not provide files already visited</li>
</ul>
<p>
20170703.01:
</p>
<ul class="org-ul">
<li>fixed recentf-exclude list, now REALLY ignores unreadables</li>
<li>added export for easier export and commit of dot-emacs</li>
<li>added tvd-suggest-jump to jump between input and output</li>
</ul>
<p>
20170707.01:
</p>
<ul class="org-ul">
<li>added C-x 4 to split fram into 4 windows</li>
<li>fixed config-general-mode config</li>
<li>fixed 'emacs-change-log (didn't expand trees before work)</li>
<li>fix python loading</li>
</ul>
<p>
20170711.01:
</p>
<ul class="org-ul">
<li>fixed outshine: only loaded with elisp</li>
<li>fixed tvd-outshine-jump: use imenu if outside outshine</li>
<li>fixed kill-all-buffers: restore scratch after killing all buffers</li>
<li>do not ask to save abbrevs on exit anymore</li>
<li>reformat changelog</li>
<li>rm open-line-below</li>
</ul>
<p>
20170711.02:
</p>
<ul class="org-ul">
<li>fixed POD abbrevs, added way to move point after expansion</li>
</ul>
<p>
20170712.01:
</p>
<ul class="org-ul">
<li>disabled org mode superscripts</li>
<li>+ winner mode</li>
<li>org mode 'code new binding: C-c 0</li>
<li>fixed emacs-change-log</li>
<li>added tvd-outshine-end-of-section incl speed command</li>
</ul>
<p>
20170712.02:
</p>
<ul class="org-ul">
<li>fixed tvd-outshine-end-of-section, it's way faster now and
works without narrowing.</li>
</ul>
<p>
20170714.01:
</p>
<ul class="org-ul">
<li>fixed pod-mode abbrev cursor jumping if no jump pos exists</li>
<li>fix initial-buffer-choice</li>
<li>added mmm-mode</li>
<li>added here-doc support to config-general using mmm-mode</li>
<li>made outline faces a little bigger, added face for level 4</li>
<li>rm initial buffer, doesnt open commandline files anymore with this</li>
<li>finally initial buffer works, opens command line file or text scratch</li>
</ul>
<p>
20170715.01:
</p>
<ul class="org-ul">
<li>no more MMM for C::G, destroys indent</li>
<li>incorporated my C::G customizations, Steve Purcell removed from
it because inappropriate,
<a href="https://github.com/TLINDEN/config-general-mode/commit/d7e8323">see d7e8323</a></li>
<li>fixed autoscratch hook</li>
<li>add scratch alias</li>
</ul>
<p>
20170718.01:
</p>
<ul class="org-ul">
<li>better autoscratch config</li>
<li>added persistent-scratch mode</li>
</ul>
<p>
20170719.01:
</p>
<ul class="org-ul">
<li>fixed electric-indent in autoscratch config</li>
<li>use my own autoscratch triggers</li>
<li>kill-all-buffers now uses 'autoscratch-buffer</li>
<li>renamce autoscratch</li>
<li>tuned recenter-positions</li>
</ul>
<p>
20170722.01:
</p>
<ul class="org-ul">
<li>added followcursor-mode</li>
</ul>
<p>
20170724.01:
</p>
<ul class="org-ul">
<li>added ido completion for tramp hostnames</li>
</ul>
<p>
20170725.01:
</p>
<ul class="org-ul">
<li>autoscratch lambda=&gt;progn</li>
<li>added sort-table-ip[desc] and fixed auto-alignment so
that ip's are left aligned</li>
<li>+req org-table</li>
</ul>
<p>
20170727.01:
</p>
<ul class="org-ul">
<li>+magit</li>
<li>configured magit dirs</li>
<li>+magit ido</li>
<li>fix magit info dir</li>
</ul>
<p>
20170730.01
</p>
<ul class="org-ul">
<li>+some magit navigation keys</li>
</ul>
<p>
20170731.01
</p>
<ul class="org-ul">
<li>do not load magit on w32</li>
<li>Always call `magit-status' with prefix arg</li>
<li>do bigger jumps in magit with just C-&lt;up|down&gt;</li>
<li>add "ls" to magit-status leading to dired</li>
</ul>
<p>
20170801.01
</p>
<ul class="org-ul">
<li>added C command to magit to switch repo</li>
<li>add : trigger for ido-find-file to begin with tramp</li>
</ul>
<p>
20170802.01
</p>
<ul class="org-ul">
<li>+table-to-excel</li>
<li>added some git wrappers to dired to add or rm files</li>
</ul>
<p>
20170805.01
</p>
<ul class="org-ul">
<li>+C-c C-c for rename files in dired</li>
</ul>
<p>
20170807.01
</p>
<ul class="org-ul">
<li>added dired config and functions</li>
<li>added dired-hacks: ranger and filters, enhanced navigation commands</li>
</ul>
<p>
20170808.01
</p>
<ul class="org-ul">
<li>(i) is now a function, not an alias anymore and more comfortable</li>
<li>added org info path</li>
<li>added info+</li>
</ul>
<p>
20170821.01
</p>
<ul class="org-ul">
<li>highlight line color light green with default bg</li>
</ul>
<p>
20170901.01
</p>
<ul class="org-ul">
<li>added :jump-to-captured to org capture templates,
didn't know about it before</li>
</ul>
<p>
20170913.01
</p>
<ul class="org-ul">
<li>disabled outline in config-general-mode</li>
</ul>
<p>
20170924.01
</p>
<ul class="org-ul">
<li>experimenting swiper</li>
</ul>
<p>
20171201.01
</p>
<ul class="org-ul">
<li>highlight TABs with ruby as well</li>
</ul>
<p>
20171205.01
</p>
<ul class="org-ul">
<li>fixed ORG template headings</li>
</ul>
<p>
20180210.01
</p>
<ul class="org-ul">
<li>added ediff config</li>
<li>fixed ob-sh to ob-shell</li>
</ul>
<p>
20180730.01
</p>
<ul class="org-ul">
<li>added autoscratch-reset-default-directory t</li>
</ul>
<p>
20181004.01
</p>
<ul class="org-ul">
<li>added projectile and config</li>
<li>added hydra and config (for org tables and projectile)</li>
<li>finished org table hydra</li>
<li>added info hydra, fixed 't bug</li>
</ul>
<p>
20181016.01
</p>
<ul class="org-ul">
<li>fixed dired under cygwin w/o git</li>
</ul>
<p>
20181019.01
</p>
<ul class="org-ul">
<li>using C-x for all hydras now:
C-x w: windows
C-x t: org table
C-y p: projectile</li>
<li>added copy org table row</li>
<li>enhanced window hyrda by resizing chords</li>
<li>changed table copy key chords (C-c t [ctr]</li>
</ul>
<ul class="org-ul">
<li>better windows hydra</li>
<li>on help close restore windows setup</li>
<li>fixed hydra hints</li>
</ul>
<p>
20181021.01
</p>
<ul class="org-ul">
<li>fixed window resizing</li>
</ul>
<p>
20181022.01
</p>
<ul class="org-ul">
<li>enhanced M-o for window switching a lot, using a hydra and the arrow keys</li>
</ul>
<p>
20181029.01
</p>
<ul class="org-ul">
<li>fixed recentf max files</li>
</ul>
<p>
20181030.01
</p>
<ul class="org-ul">
<li>fixed windows hydra flip window call</li>
</ul>
<p>
20181105.01
</p>
<ul class="org-ul">
<li>added eyebrowse with config and hydra, prefix: C-x C-x</li>
</ul>
<p>
20181106.01
</p>
<ul class="org-ul">
<li>close help windows regularly again</li>
</ul>
<p>
20181107.01
</p>
<ul class="org-ul">
<li>removed debug toggle</li>
<li>added magit status window new "q" feature which kills
all magit buffers and restores window setup</li>
<li>added magit status margin timestamps</li>
</ul>
<p>
20181107.01
</p>
<ul class="org-ul">
<li>fixed function, inserts at ()</li>
<li>added / to dired hydra</li>
</ul>
<p>
20181110.01
</p>
<ul class="org-ul">
<li>fixed % function, really</li>
<li>fixed elisp autoscratch config</li>
</ul>
<p>
20181111.01
</p>
<ul class="org-ul">
<li>fixed autoscratch elisp trigger</li>
<li>started with smartparens, first config just replaces paredit</li>
</ul>
<p>
20181113.01
</p>
<ul class="org-ul">
<li>disabled paredit, enabled smartparens</li>
</ul>
<p>
20181115.01
</p>
<ul class="org-ul">
<li>disabled smartparens strict mode, much annoying</li>
<li>map C-k to 'sp-kill-hybrid-sexp</li>
</ul>
<p>
20181117.01
</p>
<ul class="org-ul">
<li>disabled outline C-&lt;left&gt; it overwrote sp slurp left</li>
<li>enhanced emacs-changelog</li>
<li>fixed parens bug, added sp ti monibuffer</li>
<li>added tvd-lisp-comment</li>
<li>(re-)added electric pair mode to eval-expression</li>
<li>diret -lt</li>
</ul>
<p>
20181121.01
</p>
<ul class="org-ul">
<li>added org agenda</li>
</ul>
<p>
20181122.01
</p>
<ul class="org-ul">
<li>+ new agenda o function</li>
</ul>
<p>
20181126.01
</p>
<ul class="org-ul">
<li>unlimited recentf</li>
</ul>
<p>
20181127.01
</p>
<ul class="org-ul">
<li>fixed tvd-replace-all</li>
<li>fixed agenda capture template</li>
</ul>
<p>
20181127.02
</p>
<ul class="org-ul">
<li>fixed C-up|down in agenda</li>
</ul>
<p>
20181206.01
</p>
<ul class="org-ul">
<li>added support for scheduled agenda entries and fixed tvd-replace-all
(I already had this in 20181123 but overwrote it somehow!)</li>
</ul>
<p>
20181210.01
</p>
<ul class="org-ul">
<li>fixed agenda g command</li>
</ul>
<p>
20181212.01
</p>
<ul class="org-ul">
<li>configured agenda sorting</li>
</ul>
<p>
20181212.02
</p>
<ul class="org-ul">
<li>fixed agenda sorting, must be global</li>
</ul>
<p>
20181220.01
</p>
<ul class="org-ul">
<li>added org table move cells functions</li>
</ul>
<p>
20181222.01
</p>
<ul class="org-ul">
<li>removed duplicate key bindings, added via comment</li>
</ul>
<p>
20181227.01
</p>
<ul class="org-ul">
<li>ena variable pitch w/ org, turned face config into theme</li>
</ul>
<p>
20190108.01
</p>
<ul class="org-ul">
<li>added server</li>
</ul>
<p>
20190112.01
</p>
<ul class="org-ul">
<li>added wdired cleanup function</li>
</ul>
<p>
20190112.02
</p>
<ul class="org-ul">
<li>enhanced cleaner</li>
</ul>
<p>
20190114.01
</p>
<ul class="org-ul">
<li>disabled variable pitch, annoys me</li>
</ul>
<p>
20190214.01
</p>
<ul class="org-ul">
<li>fixed C-c C-c in shell-script-mode</li>
</ul>
<p>
20190226.01
</p>
<ul class="org-ul">
<li>unbound F6 and F5 from cperl mode</li>
</ul>
<p>
20190412.01
</p>
<ul class="org-ul">
<li>added yaml mode and highlight indent mode</li>
</ul>
<p>
20190513.01
</p>
<ul class="org-ul">
<li>added scheduled task org capture template along with wrappers etc</li>
</ul>
<p>
20190520.01
</p>
<ul class="org-ul">
<li>fixed 'n' in agenda, added 'k', fixed scheduled task template</li>
</ul>
<p>
20190521.01
</p>
<ul class="org-ul">
<li>split agenda window left</li>
</ul>
<p>
20190705.01
</p>
<ul class="org-ul">
<li>added smerge hydra plus alias 'merge</li>
<li>fixed window resize hydra help</li>
</ul>
<p>
20200902.01
</p>
<ul class="org-ul">
<li>added rust mode</li>
</ul>
2020-09-04 18:47:46 +02:00
<p>
20200904.01
</p>
<ul class="org-ul">
<li>rust+smartparens</li>
</ul>
2020-11-26 20:56:59 +01:00
<p>
20190923.01
</p>
<ul class="org-ul">
<li>added RCS</li>
</ul>
2020-11-26 20:58:22 +01:00
<p>
20201126.01
</p>
<ul class="org-ul">
<li>-gh</li>
</ul>
2021-05-01 13:15:16 +02:00
<p>
20210501.01
</p>
<ul class="org-ul">
<li>added golang support</li>
</ul>
2020-09-02 20:44:21 +02:00
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgd980427" class="outline-3">
<h3 id="orgd980427"><span class="section-number-3">2.2</span> <span class="todo TODO">TODO</span> </h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-2-2">
<ul class="org-ul">
<li>check helpful <a href="https://github.com/wilfred/helpful">https://github.com/wilfred/helpful</a></li>
<li>check no-littering <a href="https://github.com/tarsius/no-littering">https://github.com/tarsius/no-littering</a></li>
<li>put tvd-ci-* stuff into mcyt</li>
<li>check <a href="https://github.com/Wilfred/refine">https://github.com/Wilfred/refine</a>
<a href="https://github.com/Wilfred/emacs-refactor">https://github.com/Wilfred/emacs-refactor</a></li>
<li>check <a href="https://github.com/Malabarba/speed-of-thought-lisp">https://github.com/Malabarba/speed-of-thought-lisp</a></li>
<li><a href="https://github.com/tkf/emacs-jedi">https://github.com/tkf/emacs-jedi</a></li>
</ul>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org9e19170" class="outline-3">
<h3 id="org9e19170"><span class="section-number-3">2.3</span> Parking Lot / Snippets</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-2-3">
<p>
Snippets which maybe of use in the future
</p>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgc7e0259" class="outline-4">
<h4 id="orgc7e0259"><span class="section-number-4">2.3.1</span> buffer-local hook</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-2-3-1">
<p>
(with-current-buffer (get-buffer "<b>scratch</b>")
(add-hook 'kill-buffer-hook
(lambda () (error "DENIED! don't kill my precious <b>scratch</b>!!"))
nil t))
</p>
<hr />
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org38567ce" class="outline-3">
<h3 id="org38567ce"><span class="section-number-3">2.4</span> .emacs config version</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-2-4">
<p>
My emacs config has a version (consisting of a timestamp with a
serial), which I display in the mode line. So I can clearly see, if
I'm using an outdated config somewhere.
</p>
<div class="org-src-container">
2021-05-01 13:15:16 +02:00
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">tvd-emacs-version</span> <span style="color: #ff0000;">"20210501.01"</span>)
2020-09-02 20:44:21 +02:00
</pre>
</div>
<hr />
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org03939f5" class="outline-2">
<h2 id="org03939f5"><span class="section-number-2">3</span> System Specifics</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-3">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-orgd6226f1" class="outline-3">
<h3 id="orgd6226f1"><span class="section-number-3">3.1</span> Global init file+dir vars, portable</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-1">
<ul class="org-ul">
<li>added dev function which opens a new development frame</li>
</ul>
<p>
since I always use ~/.emacs as my init file, this results in the
correct emacs dir:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> user-init-dir (expand-file-name (concat user-init-file <span style="color: #ff0000;">".d"</span>)))
</pre>
</div>
<p>
<i>FIXME</i>: use (pwd) to determine .emacs.d, make it more portable
use different init dir on cygwin systems
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-win-home <span style="color: #ff0000;">"C:/Cygwin/home/iz00468"</span>)
(<span style="color: #0000ff;">if</span> (file-exists-p tvd-win-home)
(<span style="color: #0000ff;">setq</span> user-init-dir (expand-file-name <span style="color: #ff0000;">".emacs.d"</span> tvd-win-home))
(<span style="color: #0000ff;">setq</span> tvd-win-home nil))
</pre>
</div>
<p>
all modes and extensions are located here
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-lisp-dir (expand-file-name <span style="color: #ff0000;">"lisp"</span> user-init-dir))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orge74e7c4" class="outline-3">
<h3 id="orge74e7c4"><span class="section-number-3">3.2</span> Shortcut Mode - mode specific help about my own customizations</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-2">
<p>
<i>FIXME</i>: complete
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">add-shortcut</span> (mode help)
(add-to-list <span style="color: #ff00ff;">'shortcut-alist</span> '(mode . help)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">shortcut</span> ()
(<span style="color: #0000ff;">interactive</span>)
(message (<span style="color: #0000ff;">cdr</span> (assoc major-mode <span style="color: #ff00ff;">'shortcut-alist</span>))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org491fc9b" class="outline-3">
<h3 id="org491fc9b"><span class="section-number-3">3.3</span> Fontlock-mode - use syntax highlighting on graphical displays</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-3">
<p>
look: <a href="https://www.emacswiki.org/emacs/CustomizingBoth">emacswiki</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> window-system
(<span style="color: #0000ff;">progn</span>
(global-font-lock-mode 1)
(set-background-color <span style="color: #ff0000;">"white"</span>)
(set-foreground-color <span style="color: #ff0000;">"DarkBlue"</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org1fc5603" class="outline-3">
<h3 id="org1fc5603"><span class="section-number-3">3.4</span> line-cursor in console</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-4">
<p>
better visibility of cursor in console sessions
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">unless</span> (display-graphic-p)
(global-hl-line-mode)
(set-face-background hl-line-face <span style="color: #ff0000;">"DarkGray"</span>)
(set-face-foreground hl-line-face <span style="color: #ff0000;">"Black"</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org5145e0b" class="outline-3">
<h3 id="org5145e0b"><span class="section-number-3">3.5</span> Backup Config</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-5">
<p>
I save backup files in a central location below the init dir, that
way they don't clutter productive file systems or repos.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-backup-directory (expand-file-name <span style="color: #ff0000;">"backups"</span> user-init-dir))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (file-exists-p tvd-backup-directory))
(make-directory tvd-backup-directory t))
</pre>
</div>
<p>
there's even a trash
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-trash-directory (expand-file-name <span style="color: #ff0000;">"trash"</span> tvd-backup-directory))
</pre>
</div>
<p>
actual configuration of all things backup related:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> make-backup-files t <span style="color: #006400;">; </span><span style="color: #006400;">backup of a file the first time it is saved.</span>
backup-by-copying t <span style="color: #006400;">; </span><span style="color: #006400;">don't clobber symlinks</span>
version-control t <span style="color: #006400;">; </span><span style="color: #006400;">version numbers for backup files</span>
delete-old-versions t <span style="color: #006400;">; </span><span style="color: #006400;">delete excess backup files silently</span>
delete-by-moving-to-trash t
kept-old-versions 6 <span style="color: #006400;">; </span><span style="color: #006400;">oldest versions to keep when a new numbered backup is made (default: 2)</span>
kept-new-versions 9 <span style="color: #006400;">; </span><span style="color: #006400;">newest versions to keep when a new numbered backup is made (default: 2)</span>
auto-save-default t <span style="color: #006400;">; </span><span style="color: #006400;">auto-save every buffer that visits a file</span>
auto-save-timeout 20 <span style="color: #006400;">; </span><span style="color: #006400;">number of seconds idle time before auto-save (default: 30)</span>
auto-save-interval 200 <span style="color: #006400;">; </span><span style="color: #006400;">number of keystrokes between auto-saves (default: 300)</span>
delete-by-moving-to-trash t
trash-directory tvd-trash-directory
backup-directory-alist `((<span style="color: #ff0000;">"emacs.d/</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">recentf</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">ido.last</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">places</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">"</span> . nil) <span style="color: #006400;">; </span><span style="color: #006400;">do not backup state files</span>
(<span style="color: #ff0000;">"."</span> . ,tvd-backup-directory))) <span style="color: #006400;">; </span><span style="color: #006400;">backup everything else</span>
</pre>
</div>
<p>
However, if the file to be backed up is remote, backup
per remote directory. that way, no root owned files end
up in my home directory, ready to be read by everyone.
This is system specific and only matches special host names.
<i>FIXME</i>: find out programatically hostname und remote user to make this generic
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(advice-add <span style="color: #ff00ff;">'make-backup-file-name-1</span> <span style="color: #8a2be2;">:before</span>
'(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> file)
(<span style="color: #0000ff;">let</span> ((filename (<span style="color: #0000ff;">car</span> file)))
(<span style="color: #0000ff;">if</span> (string-match <span style="color: #ff0000;">"</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">/ssh:.devel[0-9]+</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">:/"</span> filename)
(<span style="color: #0000ff;">setq</span> backup-directory-alist `((<span style="color: #ff0000;">"."</span> . ,(concat (match-string 1 filename) <span style="color: #ff0000;">":/root/.emacs.d/backups"</span>))))
(<span style="color: #0000ff;">setq</span> backup-directory-alist `((<span style="color: #ff0000;">"."</span> . ,tvd-backup-directory)))))))
</pre>
</div>
<p>
<i>FIXME</i>: and/or check <a href="https://www.gnu.org/software/tramp/#Auto_002dsave-and-Backup">gnu.org</a>
</p>
<ul class="org-ul">
<li>tramp-default-proxies-alist</li>
</ul>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org7771b39" class="outline-3">
<h3 id="org7771b39"><span class="section-number-3">3.6</span> console backspace fix</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-6">
<p>
make backspace work in console sessions
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key key-translation-map [?\C-h] [?\C-?])
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org2ec7557" class="outline-3">
<h3 id="org2ec7557"><span class="section-number-3">3.7</span> hide menu- and tool-bar</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-7">
<p>
I prefer a bare bones emacs window without any distractions, so turn them off.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(menu-bar-mode -1)
(tool-bar-mode -1)
(<span style="color: #0000ff;">setq</span> use-dialog-box nil)
(scroll-bar-mode 0)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgcb01af2" class="outline-3">
<h3 id="orgcb01af2"><span class="section-number-3">3.8</span> stay silent on startup</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-8">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> initial-scratch-message <span style="color: #ff0000;">""</span>)
(<span style="color: #0000ff;">setq</span> inhibit-startup-message t)
(<span style="color: #0000ff;">setq</span> inhibit-startup-screen t)
(<span style="color: #0000ff;">setq</span> inhibit-startup-echo-area-message <span style="color: #ff0000;">"scip"</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org858e9d5" class="outline-3">
<h3 id="org858e9d5"><span class="section-number-3">3.9</span> y means yes</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-9">
<p>
y is shorter than yes and less error prone.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'yes-or-no-p</span> <span style="color: #ff00ff;">'y-or-n-p</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org2f41c16" class="outline-3">
<h3 id="org2f41c16"><span class="section-number-3">3.10</span> show col in modeline</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-10">
<p>
very useful to know current column
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(column-number-mode t)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgf9b1aba" class="outline-3">
<h3 id="orgf9b1aba"><span class="section-number-3">3.11</span> file or buffer in title</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-11">
<p>
this can be seen in xmobar
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> frame-title-format '(buffer-file-name <span style="color: #ff0000;">"emacs %f"</span> (<span style="color: #ff0000;">"emacs %b"</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org9aff8c5" class="outline-3">
<h3 id="org9aff8c5"><span class="section-number-3">3.12</span> avoid invalid files</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-12">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> require-final-newline t)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orga4aa3c4" class="outline-3">
<h3 id="orga4aa3c4"><span class="section-number-3">3.13</span> prepare load-path</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-13">
<p>
where to look for extensions:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'load-path</span> tvd-lisp-dir)
(<span style="color: #0000ff;">if</span> (null tvd-win-home)
(add-to-list <span style="color: #ff00ff;">'load-path</span> (expand-file-name <span style="color: #ff0000;">"compat"</span> tvd-lisp-dir)))
</pre>
</div>
<p>
modules
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir <span style="color: #ff0000;">"/er"</span>))
(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir <span style="color: #ff0000;">"/org/lisp"</span>))
(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir <span style="color: #ff0000;">"/ivy"</span>))
(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir <span style="color: #ff0000;">"/doremi"</span>))
(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir <span style="color: #ff0000;">"/org/contrib/lisp"</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb10a9bf" class="outline-3">
<h3 id="orgb10a9bf"><span class="section-number-3">3.14</span> Hydra</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-14">
<p>
Used here and there below, loaded as early as possible
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'hydra</span>)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgc67eaac" class="outline-3">
<h3 id="orgc67eaac"><span class="section-number-3">3.15</span> byte-compile all of them, if needed</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-15">
<p>
handy function to recompile all lisp files
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">recompile-el</span>()
(<span style="color: #0000ff;">interactive</span>)
(byte-recompile-directory tvd-lisp-dir 0))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org970a297" class="outline-3">
<h3 id="org970a297"><span class="section-number-3">3.16</span> increase fontsize with ctrl-+ and ctrl--</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-16">
<p>
I use those bindings everywhere (firefox, terminal, etc), and in
emacs as well.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-global-font-size-bigger</span> ()
<span style="color: #cd6600;">"Make font size larger."</span>
(<span style="color: #0000ff;">interactive</span>)
(text-scale-increase 0.5))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-global-font-size-smaller</span> ()
<span style="color: #cd6600;">"Change font size back to original."</span>
(<span style="color: #0000ff;">interactive</span>)
(text-scale-increase -0.5))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-+"</span>) <span style="color: #ff00ff;">'tvd-global-font-size-bigger</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Schrift groesser</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C--"</span>) <span style="color: #ff00ff;">'tvd-global-font-size-smaller</span>) <span style="color: #006400;">; </span><span style="color: #006400;">kleiner</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgcaa0c3d" class="outline-3">
<h3 id="orgcaa0c3d"><span class="section-number-3">3.17</span> WINDOW management stuff</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-17">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org28deae0" class="outline-4">
<h4 id="org28deae0"><span class="section-number-4">3.17.1</span> resize windows by keyboard</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-17-1">
<p>
Very practical: resize windows easily.
</p>
<p>
hit C-c C-r then use cursor keys to resize, &lt;ret&gt; to finish
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'windresize</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-r"</span>) <span style="color: #ff00ff;">'windresize</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Split Buffer Groesse Aendern</span>
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org7d74ca0" class="outline-4">
<h4 id="org7d74ca0"><span class="section-number-4">3.17.2</span> switch windows with MS-WINDOWS key</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-17-2">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'windmove</span>)
(windmove-default-keybindings <span style="color: #ff00ff;">'super</span>)
(<span style="color: #0000ff;">setq</span> windmove-wrap-around t)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org263bafa" class="outline-4">
<h4 id="org263bafa"><span class="section-number-4">3.17.3</span> M-o switch window or buffer</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-17-3">
<p>
The key M-o has different functions depending on context:
</p>
<p>
If there's only 1 window open, switch to the last active.
</p>
<p>
If there are 2 windows open, switch back and forth between the
two. In order to flip them, Use M-O (that is: ALT+shift+o).
</p>
<p>
And if there are more than 2 windows open, call the hydra, which
allows to switch to another window using the arrow keys. The hydra
stays for 1 second unles an arrow key has been pressed. So, I can
press multiple arrow keys in a row as long as I'm fast enough
between key presses. If I stop,the hydra disappears and I end up
whereever I was last.
</p>
<p>
Also, within the hydra 'o' jumps to the last active window and
'f' flips all windows.
</p>
<p>
from <a href="https://github.com/lukhas/buffer-move">https://github.com/lukhas/buffer-move</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'buffer-move</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-previous-window</span> (<span style="color: #483d8b;">&amp;optional</span> ignore)
<span style="color: #cd6600;">"Toggle between the last two selected windows."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((win (get-mru-window t t t)))
(<span style="color: #0000ff;">unless</span> win (<span style="color: #ff0000; font-weight: bold;">error</span> <span style="color: #ff0000;">"Last window not found."</span>))
(select-window win)))
</pre>
</div>
<p>
via
<a href="http://whattheemacsd.com/buffer-defuns.el-02.html">whattheemacs.d</a>:
exchange left with right buffer (or up and down), love it.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-flip-windows</span> ()
<span style="color: #cd6600;">"Rotate your windows"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">cond</span> ((<span style="color: #0000ff;">not</span> (&gt; (count-windows)1))
(message <span style="color: #ff0000;">"You can't rotate a single window!"</span>))
(t
(<span style="color: #0000ff;">setq</span> i 1)
(<span style="color: #0000ff;">setq</span> numWindows (count-windows))
(<span style="color: #0000ff;">while</span> (&lt; i numWindows)
(<span style="color: #0000ff;">let*</span> (
(w1 (elt (window-list) i))
(w2 (elt (window-list) (+ (% i numWindows) 1)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2))
)
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1)
(<span style="color: #0000ff;">setq</span> i (1+ i)))))))
(<span style="color: #0000ff;">defhydra</span> hydra-switch-windows (<span style="color: #8a2be2;">:color</span> pink: <span style="color: #8a2be2;">:timeout</span> 2.5)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">Switch to buffer: &#8592; &#8593; &#8594; &#8595; | _o_: previous | _f_: flip | MOVE: _u_: up _d_: down _l_: left _r_: right"</span>
(<span style="color: #ff0000;">"&lt;up&gt;"</span> windmove-up nil)
(<span style="color: #ff0000;">"&lt;down&gt;"</span> windmove-down nil)
(<span style="color: #ff0000;">"&lt;left&gt;"</span> windmove-left nil)
(<span style="color: #ff0000;">"&lt;right&gt;"</span> windmove-right nil)
(<span style="color: #ff0000;">"o"</span> tvd-previous-window nil <span style="color: #8a2be2;">:color</span> blue)
(<span style="color: #ff0000;">"f"</span> tvd-flip-windows nil <span style="color: #8a2be2;">:color</span> blue)
(<span style="color: #ff0000;">"u"</span> buf-move-up nil <span style="color: #8a2be2;">:color</span> blue)
(<span style="color: #ff0000;">"d"</span> buf-move-down nil <span style="color: #8a2be2;">:color</span> blue)
(<span style="color: #ff0000;">"l"</span> buf-move-left nil <span style="color: #8a2be2;">:color</span> blue)
(<span style="color: #ff0000;">"r"</span> buf-move-right nil <span style="color: #8a2be2;">:color</span> blue)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
</pre>
</div>
<p>
via <a href="http://mbork.pl/2017-02-26_other-window-or-switch-buffer">mbork</a>
modified to call the above hydra if there are more than 2 windows
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">other-window-or-switch-buffer</span> ()
<span style="color: #cd6600;">"Call `</span><span style="color: #cd6600;">other-window</span><span style="color: #cd6600;">' if more than one window is visible, switch</span>
<span style="color: #cd6600;">to next buffer otherwise."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (one-window-p)
(switch-to-buffer nil)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> (= (length (window-list)) 2)
(other-window 1)
(hydra-switch-windows/body)))))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-o"</span>) <span style="color: #ff00ff;">'other-window-or-switch-buffer</span>)
</pre>
</div>
<p>
M-o doesn't work when using emacs via Win-&gt;RDP-&gt;VNC-&gt;X11-&gt;Xmonad,
so fall back to C-o.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-o"</span>) <span style="color: #ff00ff;">'other-window-or-switch-buffer</span>)
</pre>
</div>
<p>
Use only in X11 emacs - setting M-O inside console causes &lt;up&gt; and
&lt;down&gt; to stop working properly, for whatever reasons.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (display-graphic-p)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-O"</span>) <span style="color: #ff00ff;">'tvd-flip-windows</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org904b6eb" class="outline-4">
<h4 id="org904b6eb"><span class="section-number-4">3.17.4</span> Split window to 4 parts</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-17-4">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-quarter-windows</span> ()
(<span style="color: #0000ff;">interactive</span>)
(split-window-vertically)
(split-window-horizontally)
(windmove-down)
(split-window-horizontally))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x 4"</span>) <span style="color: #ff00ff;">'tvd-quarter-windows</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgbc09849" class="outline-4">
<h4 id="orgbc09849"><span class="section-number-4">3.17.5</span> Remember and Restore Window Configurations - winner mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-17-5">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(winner-mode 1)
</pre>
</div>
<p>
keybindings: C-c left - winner-undo
keybindings: C-c right - winner-redo
</p>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org8572ada" class="outline-3">
<h3 id="org8572ada"><span class="section-number-3">3.18</span> re-read a modified buffer</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-18">
<p>
F5 == reload file if it has been modified by another process, shift
because Xmonad
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"S-&lt;f5&gt;"</span>) <span style="color: #006400;">; </span><span style="color: #006400;">re-read a buffer from disk (revert)</span>
(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;optional</span> force-reverting)
<span style="color: #cd6600;">"Interactive call to revert-buffer. Ignoring the auto-save</span>
<span style="color: #cd6600;"> file and not requesting for confirmation. When the current buffer</span>
<span style="color: #cd6600;"> is modified, the command refuses to revert it, unless you specify</span>
<span style="color: #cd6600;"> the optional argument: force-reverting to true."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>)
<span style="color: #006400;">;;</span><span style="color: #006400;">(message "force-reverting value is %s" force-reverting)</span>
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">or</span> force-reverting (<span style="color: #0000ff;">not</span> (buffer-modified-p)))
(revert-buffer <span style="color: #8a2be2;">:ignore-auto</span> <span style="color: #8a2be2;">:noconfirm</span>)
(<span style="color: #ff0000; font-weight: bold;">error</span> <span style="color: #ff0000;">"The buffer has been modified"</span>))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb9a20d8" class="outline-3">
<h3 id="orgb9a20d8"><span class="section-number-3">3.19</span> global TAB/Indent config</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-19">
<p>
I use spaces everywhere but Makefiles. If I encounter TABs I
replace them with spaces, if I encounter users entering TABs into
files, I block them.
</p>
<p>
<i>FIXME</i>: also check <a href="https://github.com/glasserc/ethan-wspace">ethan-wspace</a> !
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq-default</span> indent-tabs-mode nil)
(<span style="color: #0000ff;">setq-default</span> tab-width 4)
(<span style="color: #0000ff;">setq</span> indent-line-function <span style="color: #ff00ff;">'insert-tab</span>)
(<span style="color: #0000ff;">setq</span> tab-stop-list (<span style="color: #0000ff;">quote</span> (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120)))
(<span style="color: #0000ff;">setq</span> tab-always-indent <span style="color: #ff00ff;">'complete</span>) <span style="color: #006400;">; </span><span style="color: #006400;">/</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #006400;">/: doesnt work in cperl-mode</span>
(<span style="color: #0000ff;">setq</span> show-trailing-whitespace t)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">indent-buffer</span> ()
<span style="color: #006400;">;; </span><span style="color: #006400;">Author: Mathias Creutz</span>
<span style="color: #cd6600;">"Re-Indent every line in the current buffer."</span>
(<span style="color: #0000ff;">interactive</span>)
(indent-region (point-min) (point-max) nil))
</pre>
</div>
<p>
Use normal tabs in makefiles
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'makefile-mode-hook</span> '(lambda() (<span style="color: #0000ff;">setq</span> indent-tabs-mode t)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org1db95c4" class="outline-3">
<h3 id="org1db95c4"><span class="section-number-3">3.20</span> handy aliases</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-20">
<p>
M-x q r &lt;ret&gt; is short enough for me, no need for key bindings for
those
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'qrr</span> <span style="color: #ff00ff;">'query-replace-regexp</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'qr</span> <span style="color: #ff00ff;">'query-replace</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'cr</span> <span style="color: #ff00ff;">'comment-region</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ur</span> <span style="color: #ff00ff;">'uncomment-region</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ir</span> <span style="color: #ff00ff;">'indent-region</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'dv</span> <span style="color: #ff00ff;">'describe-variable</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'dk</span> <span style="color: #ff00ff;">'describe-key</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'df</span> <span style="color: #ff00ff;">'describe-function</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'dp</span> <span style="color: #ff00ff;">'describe-char</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'dm</span> <span style="color: #ff00ff;">'describe-mode</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'db</span> <span style="color: #ff00ff;">'describe-bindings</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'dl</span> <span style="color: #ff00ff;">'finder-commentary</span>) <span style="color: #006400;">; </span><span style="color: #006400;">aka "describe library"</span>
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'repl</span> <span style="color: #ff00ff;">'ielm</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ws</span> <span style="color: #ff00ff;">'window-configuration-to-register</span>) <span style="color: #006400;">; </span><span style="color: #006400;">save window config</span>
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'wr</span> <span style="color: #ff00ff;">'jump-to-register</span>) <span style="color: #006400;">; </span><span style="color: #006400;">restore window config</span>
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'rec</span> <span style="color: #ff00ff;">'rectangle-mark-mode</span>)
(<span style="color: #0000ff;">defalias</span> '<span style="color: #9932cc;">|</span> <span style="color: #ff00ff;">'shell-command-on-region</span>) <span style="color: #006400;">; </span><span style="color: #006400;">apply shell command on region</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org7b30850" class="outline-3">
<h3 id="org7b30850"><span class="section-number-3">3.21</span> various settings</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-21">
<p>
point stays while scrolling
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> scroll-preserve-screen-position t)
</pre>
</div>
<p>
no comment margins
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq-default</span> comment-column 0)
</pre>
</div>
<p>
do not save until I hit C-x-s
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> auto-save-default nil)
</pre>
</div>
<p>
show all buffers in buffer menu
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> buffers-menu-max-size nil)
</pre>
</div>
<p>
start to wrap at 30 entries
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> mouse-buffer-menu-mode-mult 30)
</pre>
</div>
<p>
I'm grown up!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> disabled-command-function nil)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orge52ff88" class="outline-3">
<h3 id="orge52ff88"><span class="section-number-3">3.22</span> load imenu</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-22">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key global-map [C-down-mouse-2] <span style="color: #ff00ff;">'imenu</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgcc5be60" class="outline-3">
<h3 id="orgcc5be60"><span class="section-number-3">3.23</span> copy/paste Config</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-23">
<p>
Related:
</p>
<ul class="org-ul">
<li>see also mark-copy-yank-things-mode below!</li>
<li>see also: move-region below (for M-&lt;up|down&gt;)</li>
<li>see also: expand-region below (for C-0)</li>
</ul>
<p>
middle mouse button paste at click not where cursor is
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> mouse-yank-at-point t)
</pre>
</div>
<p>
highlight selected stuff (also allows DEL of active region)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> transient-mark-mode t)
</pre>
</div>
<p>
pasting onto selection deletes it
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(delete-selection-mode t)
</pre>
</div>
<p>
delete whole lines
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> kill-whole-line t)
</pre>
</div>
<p>
middle-mouse and C-y use both X-selection and Emacs-clipboard
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (null tvd-win-home)
(<span style="color: #0000ff;">progn</span> <span style="color: #006400;">; </span><span style="color: #006400;">unix</span>
(<span style="color: #0000ff;">setq</span> x-select-enable-primary t)
(<span style="color: #0000ff;">setq</span> x-select-enable-clipboard nil))
(<span style="color: #0000ff;">progn</span> <span style="color: #006400;">; </span><span style="color: #006400;">win</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;up-mouse-2&gt;"</span>) <span style="color: #ff00ff;">'yank</span>)))
</pre>
</div>
<p>
marked region automatically copied, also on win
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> mouse-drag-copy-region t)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org348d202" class="outline-3">
<h3 id="org348d202"><span class="section-number-3">3.24</span> use more mem</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-24">
<p>
are you from the past?
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> gc-cons-threshold 20000000)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org21d9b27" class="outline-3">
<h3 id="org21d9b27"><span class="section-number-3">3.25</span> better file name completion</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-25">
<p>
Complete filenames case insensitive and ignore certain files during completion.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> read-file-name-completion-ignore-case t)
(<span style="color: #0000ff;">setq</span> read-buffer-completion-ignore-case t)
</pre>
</div>
<p>
via <a href="http://endlessparentheses.com/improving-emacs-file-name-completion.html">endlessparantheses</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(mapc (<span style="color: #0000ff;">lambda</span> (x)
(add-to-list <span style="color: #ff00ff;">'completion-ignored-extensions</span> x))
'(<span style="color: #ff0000;">".aux"</span> <span style="color: #ff0000;">".bbl"</span> <span style="color: #ff0000;">".blg"</span> <span style="color: #ff0000;">".exe"</span>
<span style="color: #ff0000;">".log"</span> <span style="color: #ff0000;">".meta"</span> <span style="color: #ff0000;">".out"</span> <span style="color: #ff0000;">".pdf"</span>
<span style="color: #ff0000;">".synctex.gz"</span> <span style="color: #ff0000;">".tdo"</span> <span style="color: #ff0000;">".toc"</span>
<span style="color: #ff0000;">"-pkg.el"</span> <span style="color: #ff0000;">"-autoloads.el"</span> <span style="color: #ff0000;">".elc"</span>
<span style="color: #ff0000;">".dump"</span> <span style="color: #ff0000;">".ps"</span> <span style="color: #ff0000;">".png"</span> <span style="color: #ff0000;">".jpg"</span>
<span style="color: #ff0000;">".gz"</span> <span style="color: #ff0000;">".tgz"</span> <span style="color: #ff0000;">".zip"</span>
<span style="color: #ff0000;">"Notes.bib"</span> <span style="color: #ff0000;">"auto/"</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org5a8ed25" class="outline-3">
<h3 id="org5a8ed25"><span class="section-number-3">3.26</span> abbreviations</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-26">
<p>
Do I really need those anymore? Added ca 1999&#x2026;
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-abbrev-table <span style="color: #ff00ff;">'global-abbrev-table</span> '(
(<span style="color: #ff0000;">"oe"</span> <span style="color: #ff0000;">"&amp;ouml;"</span> nil 0)
(<span style="color: #ff0000;">"ue"</span> <span style="color: #ff0000;">"&amp;uuml;"</span> nil 0)
(<span style="color: #ff0000;">"ae"</span> <span style="color: #ff0000;">"&amp;auml;"</span> nil 0)
(<span style="color: #ff0000;">"Oe"</span> <span style="color: #ff0000;">"&amp;Ouml;"</span> nil 0)
(<span style="color: #ff0000;">"Ue"</span> <span style="color: #ff0000;">"&amp;Uuml;"</span> nil 0)
(<span style="color: #ff0000;">"Ae"</span> <span style="color: #ff0000;">"&amp;Auml;"</span> nil 0)
(<span style="color: #ff0000;">"&lt;li&gt;"</span> <span style="color: #ff0000;">"&lt;li&gt; &lt;/li&gt;"</span> nil 0)
(<span style="color: #ff0000;">"&lt;ul&gt;"</span> <span style="color: #ff0000;">"&lt;ul&gt; &lt;/ul&gt;"</span> nil 0)
))
</pre>
</div>
<p>
do NOT ask to save abbrevs on exit
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> save-abbrevs nil)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org94f48b8" class="outline-3">
<h3 id="org94f48b8"><span class="section-number-3">3.27</span> meaningful names for buffers with the same name</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-27">
<p>
from (<a href="https://github.com/bbatsov/prelude">prelude</a>)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'uniquify</span>)
(<span style="color: #0000ff;">setq</span> uniquify-buffer-name-style <span style="color: #ff00ff;">'forward</span>)
(<span style="color: #0000ff;">setq</span> uniquify-separator <span style="color: #ff0000;">"/"</span>)
(<span style="color: #0000ff;">setq</span> uniquify-after-kill-buffer-p t) <span style="color: #006400;">; </span><span style="color: #006400;">rename after killing uniquified</span>
(<span style="color: #0000ff;">setq</span> uniquify-ignore-buffers-re <span style="color: #ff0000;">"^\\*"</span>) <span style="color: #006400;">; </span><span style="color: #006400;">don't muck with special buffers</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb4209ae" class="outline-3">
<h3 id="orgb4209ae"><span class="section-number-3">3.28</span> packages</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-28">
<p>
I dont need it all the time and only for experimentation, so lets
only use melpa on demand
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">toggle-melpa</span>()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'package</span>)
(add-to-list <span style="color: #ff00ff;">'package-archives</span>
'(<span style="color: #ff0000;">"melpa"</span> . <span style="color: #ff0000;">"http://melpa.org/packages/"</span>))
(<span style="color: #0000ff;">when</span> (&lt; emacs-major-version 24)
<span style="color: #006400;">;; </span><span style="color: #006400;">For important compatibility libraries like cl-lib</span>
(add-to-list <span style="color: #ff00ff;">'package-archives</span> '(<span style="color: #ff0000;">"gnu"</span> . <span style="color: #ff0000;">"http://elpa.gnu.org/packages/"</span>)))
(package-initialize)
(list-packages))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org6ac81b9" class="outline-3">
<h3 id="org6ac81b9"><span class="section-number-3">3.29</span> My own global variables</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-29">
<p>
narrowed fringe background
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">tvd-fringe-narrow-bg</span> <span style="color: #ff0000;">"OrangeRed"</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgbbee73a" class="outline-3">
<h3 id="orgbbee73a"><span class="section-number-3">3.30</span> More scratch space</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-30">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-orgfd88c99" class="outline-4">
<h4 id="orgfd88c99"><span class="section-number-4">3.30.1</span> Text scratch</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-30-1">
<p>
Sometimes I need a text mode scratch buffer while scratch is
already in use. So let's prepare one. I also add a buffer hook so that
this never gets deleted, but cleaned instead.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*text*"</span>)
(text-mode))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org78a10be" class="outline-4">
<h4 id="org78a10be"><span class="section-number-4">3.30.2</span> Autoscratch</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-30-2">
<p>
use autoscratch otherwise
<a href="https://github.com/TLINDEN/autoscratch">autoscratch github</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'autoscratch-mode</span>)
(<span style="color: #0000ff;">setq</span> initial-major-mode <span style="color: #ff00ff;">'autoscratch-mode</span>)
(add-hook <span style="color: #ff00ff;">'autoscratch-mode-hook</span> '(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">setq</span> autoscratch-triggers-alist
'((<span style="color: #ff0000;">"[(;]"</span> . (<span style="color: #0000ff;">progn</span>
(call-interactively <span style="color: #ff00ff;">'emacs-lisp-mode</span>)
(call-interactively <span style="color: #ff00ff;">'enable-paredit-mode</span>)
(call-interactively <span style="color: #ff00ff;">'electric-pair-mode</span>)))
(<span style="color: #ff0000;">"#"</span> . (<span style="color: #0000ff;">progn</span>
(call-interactively <span style="color: #ff00ff;">'config-general-mode</span>)
(electric-indent-local-mode t)))
(<span style="color: #ff0000;">"[-a-zA-Z0-9]"</span> . (text-mode))
(<span style="color: #ff0000;">"/"</span> . (c-mode))
(<span style="color: #ff0000;">"*"</span> . (<span style="color: #0000ff;">progn</span> (insert <span style="color: #ff0000;">" "</span>) (org-mode)))
(<span style="color: #ff0000;">"."</span> . (fundamental-mode)))
autoscratch-trigger-on-first-char t
autoscratch-reset-default-directory t)
(electric-indent-local-mode nil)
))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'scratch</span> <span style="color: #ff00ff;">'autoscratch-buffer</span>)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org54bbb5a" class="outline-4">
<h4 id="org54bbb5a"><span class="section-number-4">3.30.3</span> Persistent Scratch</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-3-30-3">
<p>
I also like to be scratch buffers persistent with
<a href="https://github.com/Fanael/persistent-scratch">persistent-scratch</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'persistent-scratch</span>)
(<span style="color: #0000ff;">setq</span> persistent-scratch-save-file (expand-file-name <span style="color: #ff0000;">"scratches.el"</span> user-init-dir))
(persistent-scratch-setup-default)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-autoscratch-p</span> ()
<span style="color: #cd6600;">"Return non-nil if the current buffer is a scratch buffer"</span>
(string-match <span style="color: #ff0000;">"scratch*"</span> (buffer-name)))
(<span style="color: #0000ff;">setq</span> persistent-scratch-scratch-buffer-p-function <span style="color: #ff00ff;">'tvd-autoscratch-p</span>)
</pre>
</div>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org0a83d1e" class="outline-3">
<h3 id="org0a83d1e"><span class="section-number-3">3.31</span> Recenter config</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-3-31">
<p>
<a href="http://oremacs.com/2015/03/28/recenter/">via abo abo</a>
</p>
<p>
However, I set the first position to 1, which causes the window to
be recentered on the second line, that is, I can see one line above
the current one. It works the same with bottom, which I intend, but
I think this is a recenter calculation bug.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> recenter-positions '(1 middle bottom))
</pre>
</div>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orga208ea6" class="outline-2">
<h2 id="orga208ea6"><span class="section-number-2">4</span> Global Key Bindings</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-4">
<hr />
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org9f5d04c" class="outline-3">
<h3 id="org9f5d04c"><span class="section-number-3">4.1</span> c-h != delete</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-4-1">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(keyboard-translate ?\C-h ?\C-?)
(keyboard-translate ?\C-? ?\C-h)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org01c8ac1" class="outline-3">
<h3 id="org01c8ac1"><span class="section-number-3">4.2</span> general keys (re-)mappings</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-4-2">
<p>
(global-set-key (kbd "C-s") 'isearch-forward-regexp)
(global-set-key (kbd "C-r") 'isearch-backward-regexp)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-C-s"</span>) <span style="color: #ff00ff;">'isearch-forward</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-C-r"</span>) <span style="color: #ff00ff;">'isearch-backward</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-%"</span>) <span style="color: #ff00ff;">'query-replace-regexp</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;backtab&gt;"</span>) <span style="color: #ff00ff;">'dabbrev-completion</span>) <span style="color: #006400;">; </span><span style="color: #006400;">shift-tab, inline completion</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;f9&gt;"</span>) <span style="color: #ff00ff;">'html-mode</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;delete&gt;"</span>) <span style="color: #ff00ff;">'delete-char</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Entf Char loeschen</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;backspace&gt;"</span>) <span style="color: #ff00ff;">'backward-delete-char</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Shift+Backspace dito</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"S-&lt;delete&gt;"</span>) <span style="color: #ff00ff;">'kill-word</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Shift+Entf Wort loeschen</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"S-&lt;backspace&gt;"</span>) <span style="color: #ff00ff;">'backward-kill-word</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Shift+Backspace dito</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-&lt;delete&gt;"</span>) <span style="color: #ff00ff;">'kill-word</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Shift+Entf dito</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-&lt;backspace&gt;"</span>) <span style="color: #ff00ff;">'backward-kill-word</span>) <span style="color: #006400;">; </span><span style="color: #006400;">Shift+Backspace dito</span>
(global-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-z"</span>))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x k"</span>) <span style="color: #ff00ff;">'kill-this-buffer</span>) <span style="color: #006400;">; </span><span style="color: #006400;">C-x k really kill current buffer w/o asking</span>
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-b"</span>) <span style="color: #ff00ff;">'buffer-menu</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgf836054" class="outline-3">
<h3 id="orgf836054"><span class="section-number-3">4.3</span> display a list of my own global key bindings and aliases</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-4-3">
<p>
via <a href="https://www.emacswiki.org/emacs/OccurMode#toc9">emacswiki</a>
</p>
<p>
Inside <b>Occur</b>: q - quit, e - edit, g - reload
more help with: describe-function occur-mode
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">occur-mode-clean-buffer</span> ()
<span style="color: #cd6600;">"Removes all commentary from the *Occur* buffer, leaving the</span>
<span style="color: #cd6600;"> unadorned lines."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (get-buffer <span style="color: #ff0000;">"*Occur*"</span>)
(<span style="color: #0000ff;">save-excursion</span>
(set-buffer (get-buffer <span style="color: #ff0000;">"*Occur*"</span>))
(goto-char (point-min))
(toggle-read-only 0)
(<span style="color: #0000ff;">if</span> (looking-at <span style="color: #ff0000;">"^[0-9]+ lines matching \""</span>)
(kill-line 1))
(<span style="color: #0000ff;">while</span> (re-search-forward <span style="color: #ff0000;">"^[ \t]*[0-9]+:"</span>
(point-max)
t)
(replace-match <span style="color: #ff0000;">""</span>)
(forward-line 1)))
(message <span style="color: #ff0000;">"There is no buffer named \"*Occur*\"."</span>)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">show-definition</span>(REGEX)
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((dotemacs-loaded nil)
(occur-b <span style="color: #ff0000;">"*Occur*"</span>)
(occur-c <span style="color: #ff0000;">""</span>))
(<span style="color: #0000ff;">if</span> (get-buffer <span style="color: #ff0000;">".emacs"</span>)
(<span style="color: #0000ff;">progn</span>
(switch-to-buffer <span style="color: #ff0000;">".emacs"</span>)
(<span style="color: #0000ff;">setq</span> dotemacs-loaded t))
(find-file <span style="color: #ff0000;">"~/.emacs"</span>))
(occur REGEX)
(<span style="color: #0000ff;">with-current-buffer</span> occur-b
(occur-mode-clean-buffer)
(<span style="color: #0000ff;">setq</span> occur-c (current-buffer))
(<span style="color: #0000ff;">let</span> ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) ()))
(<span style="color: #0000ff;">while</span> (re-search-forward <span style="color: #ff0000;">"[0-9]*:"</span> nil t)
(replace-match <span style="color: #ff0000;">""</span>))
(beginning-of-buffer)
(kill-line)
(sort-lines nil (point-min) (point-max))
(emacs-lisp-mode)
(beginning-of-buffer)
(insert (format <span style="color: #ff0000;">";; *SHOW*: %s\n"</span> REGEX))
(highlight-regexp REGEX)
(beginning-of-buffer))
(switch-to-buffer occur-b)
(delete-other-windows)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> dotemacs-loaded nil)
(kill-buffer <span style="color: #ff0000;">".emacs"</span>))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">show-keys</span>()
(<span style="color: #0000ff;">interactive</span>)
(show-definition <span style="color: #ff0000;">"^(global-set-key"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">show-aliases</span>()
(<span style="color: #0000ff;">interactive</span>)
(show-definition <span style="color: #ff0000;">"^(defalias"</span>))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'sk</span> <span style="color: #ff00ff;">'show-keys</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'sa</span> <span style="color: #ff00ff;">'show-aliases</span>)
</pre>
</div>
<hr />
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org1c11627" class="outline-2">
<h2 id="org1c11627"><span class="section-number-2">5</span> Productivity Functions</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-5">
<hr />
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb2f7324" class="outline-3">
<h3 id="orgb2f7324"><span class="section-number-3">5.1</span> goto line with tmp line numbers</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-1">
<p>
I stole this somewhere, as far as I remember, emacswiki, however, I
always had F7 for goto-line
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">goto-line-with-feedback</span> ()
<span style="color: #cd6600;">"Show line numbers temporarily, while prompting for the line number input"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">unwind-protect</span>
(<span style="color: #0000ff;">progn</span>
(linum-mode 1)
(call-interactively <span style="color: #ff00ff;">'goto-line</span>))
(linum-mode -1)))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;f7&gt;"</span>) <span style="color: #ff00ff;">'goto-line-with-feedback</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org50ef33c" class="outline-3">
<h3 id="org50ef33c"><span class="section-number-3">5.2</span> invert fore- and background</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-2">
<p>
Sometimes when sitting in a very dark enviroment, my usual light
emacs frame is a too stark contrast to the environment. With this
function I can just invert my current color settings to dark
background and light foreground.
</p>
<p>
remember last inverse
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">tvd-invert-state</span> t)
</pre>
</div>
<p>
invert everything, reverse it when called again
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-invert</span>()
<span style="color: #cd6600;">"invert fg-bg"</span>
(<span style="color: #0000ff;">interactive</span>)
(invert-face <span style="color: #ff00ff;">'default</span>)
(invert-face <span style="color: #ff00ff;">'mode-line</span>)
(set-face-attribute <span style="color: #ff00ff;">'fringe</span> nil <span style="color: #8a2be2;">:inverse-video</span> tvd-invert-state)
(<span style="color: #0000ff;">setq</span> tvd-invert-state (<span style="color: #0000ff;">not</span> tvd-invert-state)) <span style="color: #006400;">;; </span><span style="color: #006400;">cycle variable tvd-invert-state</span>
)
</pre>
</div>
<p>
fast
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-i"</span>) <span style="color: #ff00ff;">'tvd-invert</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org666e00e" class="outline-3">
<h3 id="org666e00e"><span class="section-number-3">5.3</span> Some useful bindings for Home and End keys Hit the key once to</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-3">
<p>
Go to the beginning/end of a line, hit it twice in a row to go to
the beginning/end of the window, three times in a row goes to the
beginning/end of the buffer. NB that there is no timeout involved.
</p>
<p>
Uses a function of viking-mode to establish key repeats, see below.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">pc-keys-home</span> ()
<span style="color: #cd6600;">"Go to beginning of line/window/buffer. First hitting key goes</span>
<span style="color: #cd6600;">to beginning of line, second in a row goes to beginning of</span>
<span style="color: #cd6600;">window, third in a row goes to beginning of buffer."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let*</span> ((key-times (viking-last-key-repeats)))
(<span style="color: #0000ff;">cond</span>
((<span style="color: #0000ff;">eq</span> key-times 3)
(<span style="color: #0000ff;">if</span> mark-active
(goto-char (point-min))
(beginning-of-buffer)))
((<span style="color: #0000ff;">eq</span> key-times 2)
(<span style="color: #0000ff;">if</span> mark-active () (push-mark))
(move-to-window-line 0))
((<span style="color: #0000ff;">eq</span> key-times 1)
(beginning-of-line)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">pc-keys-end</span> ()
<span style="color: #cd6600;">"Go to end of line/window/buffer. First hitting key goes</span>
<span style="color: #cd6600;">to end of line, second in a row goes to end of</span>
<span style="color: #cd6600;">window, third in a row goes to end of buffer."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let*</span> ((key-times (viking-last-key-repeats)))
(<span style="color: #0000ff;">cond</span>
((<span style="color: #0000ff;">eq</span> key-times 3)
(<span style="color: #0000ff;">if</span> mark-active
(goto-char (point-max))
(end-of-buffer)))
((<span style="color: #0000ff;">eq</span> key-times 2)
(<span style="color: #0000ff;">if</span> mark-active () (push-mark))
(move-to-window-line -1)
(end-of-line))
((<span style="color: #0000ff;">eq</span> key-times 1)
(end-of-line)))))
</pre>
</div>
<p>
This is the most natural use for those keys
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;home&gt;"</span>) <span style="color: #ff00ff;">'pc-keys-home</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;end&gt;"</span>) <span style="color: #ff00ff;">'pc-keys-end</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgbdb3ebb" class="outline-3">
<h3 id="orgbdb3ebb"><span class="section-number-3">5.4</span> percent function</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-4">
<p>
by Jens Heunemann: jump to percent position into current buffer
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">goto-percent</span> (p) <span style="color: #006400;">;</span><span style="color: #006400;">goto Prozentwert (0-100): F8</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"nProzent: "</span>)
(<span style="color: #0000ff;">if</span> (&gt; (point-max) 80000)
(goto-char (* (/ (point-max) 100) p)) <span style="color: #006400;">;</span><span style="color: #006400;">Ueberlauf vermeiden: (max/100)*p</span>
(goto-char (/ (* p (point-max)) 100))) <span style="color: #006400;">;</span><span style="color: #006400;">Rundungsfehler verm.: (max*p)/100</span>
(beginning-of-line))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;f8&gt;"</span>) <span style="color: #ff00ff;">'goto-percent</span>) <span style="color: #006400;">;</span><span style="color: #006400;">F8 goto percent</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org73d1e03" class="outline-3">
<h3 id="org73d1e03"><span class="section-number-3">5.5</span> Simulate vi's % (percent) function</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-5">
<p>
There's not a lot about vi[m] I like, but jumping with % to a
matching paren is one of THOSE features, I also need in emacs.
</p>
<p>
with ideas from <a href="https://www.emacswiki.org/emacs/NavigatingParentheses#toc2">emacswiki</a>
</p>
<p>
If (point) is on a paren, jump to the matching paren, otherwise,
just insert a literal ?%. Only make sense if bound to %.
Does not jump in inside () though
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">jump-paren-match-or-insert-percent</span> (arg)
<span style="color: #cd6600;">"Go to the matching parenthesis if on parenthesis. Otherwise</span>
<span style="color: #cd6600;">insert %. Mimics vi stle of % jumping to matching brace."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"p"</span>)
(<span style="color: #0000ff;">cond</span> ((looking-at <span style="color: #ff0000;">"\\s\(</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">\{</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">\\["</span>) (forward-list 1) (backward-char 1))
((<span style="color: #0000ff;">and</span> (looking-at <span style="color: #ff0000;">"\\s\)</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">\}</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">\\]"</span>)
(<span style="color: #0000ff;">not</span> (looking-back <span style="color: #ff0000;">"\\s\(</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">\{</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">\\["</span>)))
(forward-char 1) (backward-list 1))
(t (insert <span style="color: #ff0000;">"%"</span>))))
</pre>
</div>
<p>
only useful in programming modes
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key prog-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"%"</span>) <span style="color: #ff00ff;">'jump-paren-match-or-insert-percent</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgee4bdea" class="outline-3">
<h3 id="orgee4bdea"><span class="section-number-3">5.6</span> Move region</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-6">
<p>
Mark a region, then use M-up|down to move it around
via <a href="https://www.emacswiki.org/emacs/MoveRegion">emacswiki</a>
code from <a href="https://github.com/targzeta/move-lines/blob/master/move-lines.el">move-lines</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">move-lines--internal</span> (n)
(<span style="color: #0000ff;">let*</span> ((start (point)) <span style="color: #006400;">;; </span><span style="color: #006400;">The position of beginning of line of the first line</span>
(end start) <span style="color: #006400;">;; </span><span style="color: #006400;">The position of eol+\n of the end line</span>
col-init <span style="color: #006400;">;; </span><span style="color: #006400;">The current column for the first line</span>
(col-end (current-column)) <span style="color: #006400;">;; </span><span style="color: #006400;">The current column for the end line</span>
exchange_pm <span style="color: #006400;">;; </span><span style="color: #006400;">If I had exchanged point and mark</span>
delete-latest-newline) <span style="color: #006400;">;; </span><span style="color: #006400;">If I had inserted a newline at the end</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">STEP 1: Identifying the line(s) to cut.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">---</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">If region is actives, I ensure that point always is at the end of the</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">region and mark at the beginning.</span>
(<span style="color: #0000ff;">when</span> (region-active-p)
(<span style="color: #0000ff;">when</span> (&lt; (point) (mark))
(<span style="color: #0000ff;">setq</span> exchange_pm t)
(exchange-point-and-mark))
(<span style="color: #0000ff;">setq</span> start (mark)
end (point)
col-end (current-column)))
(goto-char start) (<span style="color: #0000ff;">setq</span> col-init (current-column))
(beginning-of-line) (<span style="color: #0000ff;">setq</span> start (point))
(goto-char end) (end-of-line)
<span style="color: #006400;">;; </span><span style="color: #006400;">If point == point-max, this buffers doesn't have the trailing newline.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">In this case I have to insert a newline otherwise the following</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">`</span><span style="color: #006400;">forward-char</span><span style="color: #006400;">' (to keep the "\n") will fail.</span>
(<span style="color: #0000ff;">when</span> (= (point) (point-max))
(<span style="color: #0000ff;">setq</span> delete-latest-newline t)
(insert-char ?\n) (forward-char -1))
(forward-char 1) (<span style="color: #0000ff;">setq</span> end (point))
<span style="color: #006400;">;; </span><span style="color: #006400;">STEP 2: Moving the lines.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">---</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">The region I'm cutting span from the beginning of line of the current</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">line (or current region) to the end of line + 1 (newline) of the current</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">line (or current region).</span>
(<span style="color: #0000ff;">let</span> ((line-text (delete-and-extract-region start end)))
(forward-line n)
<span style="color: #006400;">;; </span><span style="color: #006400;">If the current-column != 0, I have moved the region at the bottom of a</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">buffer doesn't have the trailing newline.</span>
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">not</span> (= (current-column) 0))
(insert-char ?\n)
(<span style="color: #0000ff;">setq</span> delete-latest-newline t))
(<span style="color: #0000ff;">setq</span> start (+ (point) col-init)) <span style="color: #006400;">;; </span><span style="color: #006400;">Now, start is the start of new region</span>
(insert line-text))
<span style="color: #006400;">;; </span><span style="color: #006400;">STEP 3: Restoring</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">---</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">I'm at the end of new region (or line) and start has setted at the</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">beginning of new region (if a region is active).</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">Restoring the end column.</span>
(forward-line -1)
(forward-char col-end)
(<span style="color: #0000ff;">when</span> delete-latest-newline
(<span style="color: #0000ff;">save-excursion</span>
(goto-char (point-max))
(delete-char -1)))
(<span style="color: #0000ff;">when</span> (region-active-p)
(<span style="color: #0000ff;">setq</span> deactivate-mark nil)
(set-mark start)
(<span style="color: #0000ff;">if</span> exchange_pm
(exchange-point-and-mark)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">move-lines-up</span> (n)
<span style="color: #cd6600;">"Moves the current line or, if region is actives, the lines surrounding</span>
<span style="color: #cd6600;">region, up by N lines, or 1 line if N is nil."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"p"</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> n nil)
(<span style="color: #0000ff;">setq</span> n 1))
(move-lines--internal (- n)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">move-lines-down</span> (n)
<span style="color: #cd6600;">"Moves the current line or, if region is actives, the lines surrounding</span>
<span style="color: #cd6600;">region, down by N lines, or 1 line if N is nil."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"p"</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> n nil)
(<span style="color: #0000ff;">setq</span> n 1))
(move-lines--internal n))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-&lt;up&gt;"</span>) <span style="color: #ff00ff;">'move-lines-up</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-&lt;down&gt;"</span>) <span style="color: #ff00ff;">'move-lines-down</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org1ed413d" class="outline-3">
<h3 id="org1ed413d"><span class="section-number-3">5.7</span> comment-uncomment region with one key binding</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-7">
<p>
via <a href="http://stackoverflow.com/a/9697222/3350881">stackoverflow</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">comment-or-uncomment-region-or-line</span> ()
<span style="color: #cd6600;">"Comments or uncomments the region or the current line if there's no active region."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> (beg end)
(<span style="color: #0000ff;">if</span> (region-active-p)
(<span style="color: #0000ff;">setq</span> beg (region-beginning) end (region-end))
(<span style="color: #0000ff;">setq</span> beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-c"</span>) <span style="color: #ff00ff;">'comment-or-uncomment-region-or-line</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orga2c274a" class="outline-3">
<h3 id="orga2c274a"><span class="section-number-3">5.8</span> search for symbol at point</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-8">
<p>
Simulate the # function of vi, marks the symbol at point, C-s then
searches for it. I use this a lot.
</p>
<p>
via <a href="http://ergoemacs.org/emacs/modernization_isearch.html">ergomacs</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">xah-search-current-word</span> ()
<span style="color: #cd6600;">"Call `</span><span style="color: #cd6600;">isearch</span><span style="color: #cd6600;">' on current word or text selection.</span>
<span style="color: #cd6600;"> 'word' here is A to Z, a to z, and hyphen and underline, independent of syntax table.</span>
<span style="color: #cd6600;">URL `[[http://ergoemacs.org/emacs/modernization_isearch.html'][ergomacs]]</span>
<span style="color: #cd6600;">Version 2015-04-09"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ( xahp1 xahp2 )
(<span style="color: #0000ff;">if</span> (use-region-p)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">setq</span> xahp1 (region-beginning))
(<span style="color: #0000ff;">setq</span> xahp2 (region-end)))
(<span style="color: #0000ff;">save-excursion</span>
(skip-chars-backward <span style="color: #ff0000;">"-_A-Za-z0-9"</span>)
(<span style="color: #0000ff;">setq</span> xahp1 (point))
(right-char)
(skip-chars-forward <span style="color: #ff0000;">"-_A-Za-z0-9"</span>)
(<span style="color: #0000ff;">setq</span> xahp2 (point))))
(<span style="color: #0000ff;">setq</span> mark-active nil)
(<span style="color: #0000ff;">when</span> (&lt; xahp1 (point))
(goto-char xahp1))
(isearch-mode t)
(isearch-yank-string (buffer-substring-no-properties xahp1 xahp2))
(message <span style="color: #ff0000;">"Now use C-s to search for it ..."</span>)
))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-#"</span>) <span style="color: #ff00ff;">'xah-search-current-word</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgebf7f5e" class="outline-3">
<h3 id="orgebf7f5e"><span class="section-number-3">5.9</span> Window Margin</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-9">
<p>
Kinda screen reader for the poor. I use this sometimes with info
or woman mode. I also use a full featured screen reader: nove-mode,
see below.
</p>
<p>
left+right margin on demand (but nothing else)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">margin</span>(m)
<span style="color: #cd6600;">"set left and right margins for better readability"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"nEnter Margin (0 to disable) [0-9]+: "</span>)
(set-window-margins (<span style="color: #0000ff;">car</span> (get-buffer-window-list (current-buffer) nil t)) m m) <span style="color: #006400;">;; </span><span style="color: #006400;">set immediately</span>
(<span style="color: #0000ff;">setq</span> left-margin-width m) <span style="color: #006400;">;; </span><span style="color: #006400;">persist until reset</span>
(<span style="color: #0000ff;">setq</span> right-margin-width m)
(message <span style="color: #ff0000;">"To reset, change Buffer or call again with arg 0."</span>)
)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgd9b8ff4" class="outline-3">
<h3 id="orgd9b8ff4"><span class="section-number-3">5.10</span> Fill and justify a paragraph</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-10">
<p>
this is just a shortcut for:
C-u 70 &lt;ret&gt; M-x fill-paragraph
but C-q is just easier to remember
</p>
<p>
however, if pressed again it un-fills the paragraph,
idea via: <a href="http://endlessparentheses.com/fill-and-unfill-paragraphs-with-a-single-key.html">endlessparentheses</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-fill-and-justify-or-unfill</span>()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((fill-column
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> last-command <span style="color: #ff00ff;">'tvd-fill-and-justify-or-unfill</span>)
(<span style="color: #0000ff;">progn</span> (<span style="color: #0000ff;">setq</span> this-command nil)
(point-max))
fill-column)))
(fill-paragraph 70)))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-q"</span>) <span style="color: #ff00ff;">'tvd-fill-and-justify-or-unfill</span>) <span style="color: #006400;">; </span><span style="color: #006400;">like M-q, which is bound to x-window-quit in xmonad: fill+justify</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb03f9b1" class="outline-3">
<h3 id="orgb03f9b1"><span class="section-number-3">5.11</span> Make a read-only copy of the current buffer</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-11">
<p>
I just create a new read-only buffer and copy the contents of the
current one into it, which can be used as backup. I use this in
cases where I need to re-factor a file and do lots of changes. With
the buffer copy I have a reference to compare without the need to
leave emacs and look at revision control diffs or the like, and if
a file is not maintained via VC anyway.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">copy-counter</span> 0)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">get-copy-buffer-name</span>()
<span style="color: #cd6600;">"return unique copy buffer name"</span>
(<span style="color: #0000ff;">let</span> ((name (concat <span style="color: #ff0000;">"*COPY "</span> (buffer-name (current-buffer)) <span style="color: #ff0000;">" (RO)"</span>)))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (get-buffer name))
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">setq</span> copy-counter (1+ copy-counter))
(concat name <span style="color: #ff0000;">"&lt;"</span> (number-to-string copy-counter) <span style="color: #ff0000;">"&gt;"</span>))
(concat name))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">copy-buffer-read-only</span>()
<span style="color: #cd6600;">"Create a read-only copy of the current buffer"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((old-buffer (current-buffer))
(new-buffer-name (get-copy-buffer-name)))
(<span style="color: #0000ff;">progn</span>
(delete-other-windows)
(split-window-horizontally)
(other-window 1)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (<span style="color: #0000ff;">eq</span> (get-buffer new-buffer-name) nil))
(kill-buffer (get-buffer new-buffer-name)))
(set-buffer (get-buffer-create new-buffer-name))
(insert-buffer-substring old-buffer)
(read-only-mode)
(switch-to-buffer new-buffer-name)
(other-window 1))))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'cp</span> <span style="color: #ff00ff;">'copy-buffer-read-only</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-p"</span>) <span style="color: #ff00ff;">'copy-buffer-read-only</span>) <span style="color: #006400;">; </span><span style="color: #006400;">make read-only buffer copy</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orge44c137" class="outline-3">
<h3 id="orge44c137"><span class="section-number-3">5.12</span> Cleanup, close all windows and kill all buffers</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-12">
<p>
From time to time I get annoyed by the many dozen buffers
opened. In such cases I like to close them all at once.
</p>
<p>
No key binding though, just in case I stumble upon it and kill my
setup accidentally.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">kill-all-buffers</span> ()
<span style="color: #cd6600;">"Kill all buffers, clean up, close all windows"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">when</span> (y-or-n-p <span style="color: #ff0000;">"Close all windows and kill all buffers?"</span>)
(delete-other-windows)
(clean-buffer-list)
(<span style="color: #0000ff;">dolist</span> (buffer (buffer-list))
(kill-buffer buffer))
(delete-minibuffer-contents)
(<span style="color: #0000ff;">if</span> (fboundp <span style="color: #ff00ff;">'tramp-cleanup-all-connections</span>)
(tramp-cleanup-all-connections))
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*text*"</span>)
(text-mode))
(autoscratch-buffer)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgfb95865" class="outline-3">
<h3 id="orgfb95865"><span class="section-number-3">5.13</span> Cleanup current buffer</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-13">
<p>
Remove TABs, leading and trailing spaces, re-indent a buffer.
</p>
<p>
via <a href="http://whattheemacsd.com/buffer-defuns.el-01.html">whattheemacs.d</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">cleanup-buffer</span> ()
<span style="color: #cd6600;">"Perform a bunch of safe operations on the whitespace content of a buffer.</span>
<span style="color: #cd6600;">Does not indent buffer, because it is used for a before-save-hook, and that</span>
<span style="color: #cd6600;">might be bad."</span>
(<span style="color: #0000ff;">interactive</span>)
(untabify (point-min) (point-max))
(delete-trailing-whitespace)
(<span style="color: #0000ff;">save-excursion</span>
(replace-regexp <span style="color: #ff0000;">"^\n\\{3,\\}"</span> <span style="color: #ff0000;">"\n\n"</span> nil (point-min) (point-max)))
(set-buffer-file-coding-system <span style="color: #ff00ff;">'utf-8</span>)
(indent-region (point-min) (point-max)))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'cb</span> <span style="color: #ff00ff;">'cleanup-buffer</span>)
</pre>
</div>
<p>
related, I use this to cleanup directories and rename files and
directories to my liking. Sometimes I get a disk or stick from
Windows users and they use every character available on their
keyboards to name files and dirs. I can't have this shit.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">cleanup-dired-buffer</span> ()
<span style="color: #cd6600;">"If inside a wdired (edit) buffer, rename everything"</span>
(<span style="color: #0000ff;">interactive</span>)
(delete-trailing-whitespace)
(<span style="color: #0000ff;">save-excursion</span>
(replace-regexp <span style="color: #ff0000;">"[\(\)'`#,_&amp;\!]"</span> <span style="color: #ff0000;">""</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">" "</span> <span style="color: #ff0000;">"-"</span> nil (point-min) (point-max))
(replace-regexp <span style="color: #ff0000;">"--*"</span> <span style="color: #ff0000;">"-"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#228;"</span> <span style="color: #ff0000;">"ae"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#246;"</span> <span style="color: #ff0000;">"oe"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#252;"</span> <span style="color: #ff0000;">"ue"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#196;"</span> <span style="color: #ff0000;">"Ae"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#214;"</span> <span style="color: #ff0000;">"Oe"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#220;"</span> <span style="color: #ff0000;">"Ue"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">"&#223;"</span> <span style="color: #ff0000;">"ss"</span> nil (point-min) (point-max))
(replace-string <span style="color: #ff0000;">".."</span> <span style="color: #ff0000;">"."</span> nil (point-min) (point-max))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">cleanup-dir</span>()
<span style="color: #cd6600;">"Cleanup wdired buffer in one whole step, used for emacsclient buffers"</span>
(<span style="color: #0000ff;">interactive</span>)
(wdired-change-to-wdired-mode)
(cleanup-dired-buffer)
(wdired-finish-edit)
(kill-this-buffer))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgf784ada" class="outline-3">
<h3 id="orgf784ada"><span class="section-number-3">5.14</span> Remove Umlauts and other crab in current buffer</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-14">
<p>
converts:
Stan Lem - ein schönes Leben &amp; sonst nix(ungekuerzte Ausgabe)
to:
Stan<sub>Lem</sub>-ein<sub>schoenes</sub><sub>Leben</sub><sub>sonst</sub><sub>nix</sub><sub>ungekuerzte</sub><sub>Ausgabe</sub>
</p>
<p>
used in dired buffers to cleanup filenames by german windows users.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">umlaute-weg</span>()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((umlaute '((&#220; . Ue)
(&#196; . Ae)
(&#214; . Oe)
(&#252; . ue)
(&#228; . ae)
(&#246; . oe)
(&#223; . ss)))
(regs (list
'(<span style="color: #ff0000;">" "</span> . <span style="color: #ff0000;">"_"</span>)
'(<span style="color: #ff0000;">"_-_"</span> . <span style="color: #ff0000;">"-"</span>)
'(<span style="color: #ff0000;">"[\(\)&amp;]"</span> . <span style="color: #ff0000;">"_"</span>)
'(<span style="color: #ff0000;">"__*"</span> . <span style="color: #ff0000;">"_"</span>)
'(<span style="color: #ff0000;">"_$"</span> . <span style="color: #ff0000;">""</span>)
)))
(<span style="color: #0000ff;">save-excursion</span>
(<span style="color: #0000ff;">dolist</span> (pair umlaute)
(replace-regexp (symbol-name (<span style="color: #0000ff;">car</span> pair))
(symbol-name (<span style="color: #0000ff;">cdr</span> pair))
nil
(point-min) (point-max)))
(<span style="color: #0000ff;">dolist</span> (reg regs)
(replace-regexp (<span style="color: #0000ff;">car</span> reg) (<span style="color: #0000ff;">cdr</span> reg) nil
(point-min) (point-max))))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org6f08c2c" class="outline-3">
<h3 id="org6f08c2c"><span class="section-number-3">5.15</span> Better newline(s)</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-15">
<p>
Add newline and jump to indent from wherever I am in the current
line, that is it is not required to be on the end of line.
</p>
<p>
via <a href="http://whattheemacsd.com/editing-defuns.el-01.html">whattheemacs.d</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">open-line-below</span> ()
(<span style="color: #0000ff;">interactive</span>)
(end-of-line)
(newline)
(indent-for-tab-command))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">open-line-above</span> ()
(<span style="color: #0000ff;">interactive</span>)
(end-of-line)
(beginning-of-line)
(newline)
(forward-line -1)
(indent-for-tab-command))
</pre>
</div>
<p>
disabled, interferes with modes.
</p>
<p>
(global-set-key (kbd "&lt;C-return&gt;") 'open-line-below)
</p>
<p>
(global-set-key (kbd "&lt;C-S-return&gt;") 'open-line-above)
</p>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org40f3b88" class="outline-3">
<h3 id="org40f3b88"><span class="section-number-3">5.16</span> Mouse Rectangle</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-16">
<p>
There's not much use for the mouse in emacs, but this gimick is
funny and works like a charm.
</p>
<p>
via <a href="http://emacs.stackexchange.com/a/7261">stackoverflow</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">mouse-start-rectangle</span> (start-event)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"e"</span>)
(deactivate-mark)
(mouse-set-point start-event)
(rectangle-mark-mode +1)
(<span style="color: #0000ff;">let</span> ((drag-event))
(<span style="color: #0000ff;">track-mouse</span>
(<span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">setq</span> drag-event (read-event))
(mouse-movement-p drag-event))
(mouse-set-point drag-event)))))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"S-&lt;down-mouse-1&gt;"</span>) <span style="color: #ff00ff;">'mouse-start-rectangle</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org05fe262" class="outline-3">
<h3 id="org05fe262"><span class="section-number-3">5.17</span> DOS &lt;=&gt; UNIX conversion helpers</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-17">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">dos2unix</span> ()
(<span style="color: #0000ff;">interactive</span>)
(set-buffer-file-coding-system <span style="color: #ff00ff;">'utf-8-unix</span>)
(message (format <span style="color: #ff0000;">"converted current buffer to %s"</span> buffer-file-coding-system)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">unix2dos</span> ()
(<span style="color: #0000ff;">interactive</span>)
(set-buffer-file-coding-system <span style="color: #ff00ff;">'utf-8-dos</span>)
(message (format <span style="color: #ff0000;">"converted current buffer to %s"</span> buffer-file-coding-system)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org1d2a610" class="outline-3">
<h3 id="org1d2a610"><span class="section-number-3">5.18</span> helper do add the same thing to multiple mode hooks</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-18">
<p>
via <a href="http://stackoverflow.com/posts/3900056/revisions">stackoverflow</a>
usage samples below.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">add-something-to-mode-hooks</span> (mode-list something)
<span style="color: #cd6600;">"helper function to add a callback to multiple hooks"</span>
(<span style="color: #0000ff;">dolist</span> (mode mode-list)
(add-hook (intern (concat (symbol-name mode) <span style="color: #ff0000;">"-mode-hook"</span>)) something)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org716474f" class="outline-3">
<h3 id="org716474f"><span class="section-number-3">5.19</span> helper to catch load errors</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-19">
<p>
Try to eval 'fn, catch errors, if any but make it possible for
emacs to continue undisturbed, used with SMEX, see below.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defmacro</span> <span style="color: #9932cc;">safe-wrap</span> (fn <span style="color: #483d8b;">&amp;rest</span> clean-up)
`(<span style="color: #0000ff;">unwind-protect</span>
(<span style="color: #0000ff;">let</span> (retval)
(<span style="color: #0000ff;">condition-case</span> ex
(<span style="color: #0000ff;">setq</span> retval (<span style="color: #0000ff;">progn</span> ,fn))
(<span style="color: #ff00ff;">'error</span>
(message (format <span style="color: #ff0000;">"Caught exception: [%s]"</span> ex))
(<span style="color: #0000ff;">setq</span> retval (cons <span style="color: #ff00ff;">'exception</span> (list ex)))))
retval)
,@clean-up))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org01e1bd9" class="outline-3">
<h3 id="org01e1bd9"><span class="section-number-3">5.20</span> Alignment Wrappers</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-20">
<p>
align-regexp is already a very usefull tool, however, sometimes I
want to repeat the alignment and I hate C-u, so here are some
wrappers to make this easier.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">align-repeat</span> (regex <span style="color: #483d8b;">&amp;optional</span> alignment)
<span style="color: #cd6600;">"Aply REGEX to all columns not just the first. Align by</span>
<span style="color: #cd6600;">ALIGNMENT which must be 'left or 'right. The default is 'left.</span>
<span style="color: #cd6600;">Right alignment:</span>
<span style="color: #cd6600;">col1 ,col2</span>
<span style="color: #cd6600;">col1 ,col2</span>
<span style="color: #cd6600;">Left alignment:</span>
<span style="color: #cd6600;">col1, col2</span>
<span style="color: #cd6600;">col1, col2"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"MRepeat Align Regex [ ]: "</span>)
(<span style="color: #0000ff;">let</span> ((spc <span style="color: #ff0000;">" "</span>)
(beg (point-min))
(end (point-max))
(areg <span style="color: #ff0000;">"%s</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">\\s-*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">"</span> <span style="color: #006400;">; </span><span style="color: #006400;">default left aligned</span>
))
(<span style="color: #0000ff;">when</span> (string= regex <span style="color: #ff0000;">""</span>)
(<span style="color: #0000ff;">setq</span> regex spc))
(<span style="color: #0000ff;">when</span> (region-active-p)
(<span style="color: #0000ff;">setq</span> beg (region-beginning))
(<span style="color: #0000ff;">setq</span> end (region-end)))
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">eq</span> alignment <span style="color: #ff00ff;">'right</span>)
(<span style="color: #0000ff;">setq</span> areg <span style="color: #ff0000;">"</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">\\s-*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">%s"</span>))
(align-regexp beg end (format areg regex) 1 1 t)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">align-repeat-left</span> (regex)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"MRepeat Left Align Regex [ ]: "</span>)
(align-regexp-repeat regex <span style="color: #ff00ff;">'left</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">align-repeat-right</span> (regex)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"MRepeat Left Align Regex [ ]: "</span>)
(align-regexp-repeat regex <span style="color: #ff00ff;">'right</span>))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org381ada7" class="outline-3">
<h3 id="org381ada7"><span class="section-number-3">5.21</span> String Helpers</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-5-21">
<p>
Some helper functions I use here and there.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-alist-keys</span> (A)
<span style="color: #cd6600;">"return a list of keys of alist A"</span>
(<span style="color: #0000ff;">let</span> ((K ()))
(<span style="color: #0000ff;">dolist</span> (e A)
(<span style="color: #0000ff;">push</span> (<span style="color: #0000ff;">car</span> e) K)
)
K))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-get-line</span> ()
<span style="color: #cd6600;">"return current line in current buffer"</span>
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-starts-with</span> (s begins)
<span style="color: #cd6600;">"Return non-nil if string S starts with BEGINS."</span>
(<span style="color: #0000ff;">cond</span> ((&gt;= (length s) (length begins))
(string-equal (substring s 0 (length begins)) begins))
(t nil)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-replace-all</span> (regex replace)
<span style="color: #cd6600;">"Replace all matches of REGEX with REPLACE in current buffer."</span>
(<span style="color: #0000ff;">interactive</span>)
(goto-char (point-min))
(<span style="color: #0000ff;">while</span> (re-search-forward regex nil t)
(replace-match replace)))
</pre>
</div>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgeef6f86" class="outline-2">
<h2 id="orgeef6f86"><span class="section-number-2">6</span> Modes</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-6">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org4d87610" class="outline-3">
<h3 id="org4d87610"><span class="section-number-3">6.1</span> Programming Languages</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-6-1">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org4c00242" class="outline-4">
<h4 id="org4c00242"><span class="section-number-4">6.1.1</span> VALA</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-1">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'vala-mode</span> <span style="color: #ff0000;">"vala-mode"</span> <span style="color: #cd6600;">"Major mode for editing Vala code."</span> t)
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.vala$"</span> . vala-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.vapi$"</span> . vala-mode))
(add-to-list <span style="color: #ff00ff;">'file-coding-system-alist</span> '(<span style="color: #ff0000;">"\\.vala$"</span> . utf-8))
(add-to-list <span style="color: #ff00ff;">'file-coding-system-alist</span> '(<span style="color: #ff0000;">"\\.vapi$"</span> . utf-8))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgc2c31d3" class="outline-4">
<h4 id="orgc2c31d3"><span class="section-number-4">6.1.2</span> rust mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-2">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'rust-mode</span> <span style="color: #ff0000;">"rust-mode"</span> nil t)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">rustlings-done</span> ()
<span style="color: #cd6600;">"I use this with rustlings"</span>
(<span style="color: #0000ff;">interactive</span>)
(search-backward <span style="color: #ff0000;">"DONE"</span>)
(move-beginning-of-line 1)
(kill-line)
(save-buffer))
(<span style="color: #0000ff;">setq</span> auto-mode-alist
(append '((<span style="color: #ff0000;">"\\.</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">rs</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">$"</span> . rust-mode))
auto-mode-alist))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgaad8f72" class="outline-4">
<h4 id="orgaad8f72"><span class="section-number-4">6.1.3</span> python mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-3">
<p>
Not much configured for python, I'm happy with the defaults as it seems :)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'python</span>)
(autoload <span style="color: #ff00ff;">'python-mode</span> <span style="color: #ff0000;">"python-mode"</span> <span style="color: #cd6600;">"Major mode for python scripts"</span> t)
(add-hook
<span style="color: #ff00ff;">'python-mode-hook</span>
(<span style="color: #0000ff;">function</span>
(<span style="color: #0000ff;">lambda</span>()
(local-set-key [delete] <span style="color: #ff00ff;">'py-electric-delete</span>)
(<span style="color: #0000ff;">setq-default</span> indent-tabs-mode nil)
(<span style="color: #0000ff;">setq</span> mode-name <span style="color: #ff0000;">"PY"</span>)
(outline-minor-mode 0) <span style="color: #006400;">;; </span><span style="color: #006400;">turn off outline here. /</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #006400;">/: find out where it's turned on!</span>
)))
(<span style="color: #0000ff;">setq</span> auto-mode-alist
(append '((<span style="color: #ff0000;">"\\.</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">py</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">$"</span> . python-mode))
auto-mode-alist))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org586f030" class="outline-4">
<h4 id="org586f030"><span class="section-number-4">6.1.4</span> Shell-Script Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-4">
<p>
C-c C-c [un-]comments everywhere, force in shell-script-mode as well
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook
<span style="color: #ff00ff;">'sh-mode-hook</span>
(<span style="color: #0000ff;">function</span>
(<span style="color: #0000ff;">lambda</span>()
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-c"</span>) <span style="color: #ff00ff;">'comment-or-uncomment-region-or-line</span>))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org42adf73" class="outline-4">
<h4 id="org42adf73"><span class="section-number-4">6.1.5</span> cperl mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-5">
<p>
I am a perl addict. I love it, therefore, emacs must be prepared
for my addiction. Most importantly, I prefer cperl instead of the
default perl mode. I do not use the cperl version delivered with
emacs though, but the latest git version.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'cperl-mode</span> <span style="color: #ff0000;">"cperl-mode"</span> <span style="color: #cd6600;">"alternate perl mode"</span> t)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'perl-mode</span> <span style="color: #ff00ff;">'cperl-mode</span>)
</pre>
</div>
<p>
enable the most important cperl features
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> cperl-indent-left-aligned-comments nil)
(<span style="color: #0000ff;">setq</span> cperl-comment-column 32)
(<span style="color: #0000ff;">setq</span> cperl-hairy t)
(<span style="color: #0000ff;">setq</span> cperl-electric-linefeed t)
(<span style="color: #0000ff;">setq</span> cperl-electric-keywords t)
(<span style="color: #0000ff;">setq</span> cperl-electric-parens t)
(<span style="color: #0000ff;">setq</span> cperl-electric-parens-string nil)
</pre>
</div>
<p>
perl special: run, compile, debug
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> perl-run-out-buffer <span style="color: #ff0000;">"*Async Shell Command*"</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">perl-kill</span> ()
<span style="color: #cd6600;">"get rid of hanging perl compile or run buffers"</span>
(<span style="color: #0000ff;">interactive</span>)
(delete-windows-on perl-run-out-buffer)
(kill-buffer perl-run-out-buffer))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">perl-run</span> (switches parameters prefix)
<span style="color: #cd6600;">"execute current perl buffer"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"sPerl-switches:\nsParameter:\nP"</span>)
(<span style="color: #0000ff;">let</span> ((file buffer-file-name))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> prefix nil)
(shell-command (concat <span style="color: #ff0000;">"perl "</span> switches <span style="color: #ff0000;">" "</span> file <span style="color: #ff0000;">" "</span> parameters <span style="color: #ff0000;">"&amp;"</span>))
(shell-command (concat <span style="color: #ff0000;">"perl -wc "</span> switches <span style="color: #ff0000;">" "</span> file <span style="color: #ff0000;">" "</span> parameters <span style="color: #ff0000;">"&amp;"</span>)))
(<span style="color: #0000ff;">save-excursion</span>
(set-buffer perl-run-out-buffer)
(<span style="color: #0000ff;">setq</span> perl-error-fontified nil
perl-error-start nil
perl-error-end nil)
(goto-char (point-min)))
))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">perl-next-error</span> ()
<span style="color: #cd6600;">"jump to next perl run error, if any"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> (line
errorfile
(window (get-buffer-window (buffer-name)))
(file buffer-file-name)
(buffer (buffer-name))
)
(select-window (display-buffer perl-run-out-buffer))
(set-buffer perl-run-out-buffer)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> perl-error-fontified t)
(<span style="color: #0000ff;">progn</span>
(set-text-properties perl-error-start perl-error-end ())
(<span style="color: #0000ff;">setq</span> perl-error-fontified nil)
)
)
(<span style="color: #0000ff;">if</span> (re-search-forward (concat <span style="color: #ff0000;">"at </span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[-a-zA-Z:0-9._~#/\\]*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;"> line </span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[0-9]*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">[.,]"</span>) (point-max) t)
()
(goto-char (point-min))
(message <span style="color: #ff0000;">"LAST ERROR, jumping to first"</span>)
(re-search-forward (concat <span style="color: #ff0000;">"at </span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[-a-zA-Z:0-9._~#/\\]*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;"> line </span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[0-9]*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">[.,]"</span>) (point-max) t)
)
(recenter)
(set-text-properties (match-beginning 1)
(match-end 2)
(list <span style="color: #ff00ff;">'face</span> font-lock-keyword-face))
(<span style="color: #0000ff;">setq</span> perl-error-fontified t
perl-error-start (match-beginning 1)
perl-error-end (match-end 2)
errorfile (buffer-substring
(match-beginning 1)
(match-end 1))
line (string-to-int (buffer-substring
(match-beginning 2)
(match-end 2))))
(select-window window)
(find-file errorfile)
(goto-line line)))
</pre>
</div>
<p>
cperl indent region
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">own-cperl-indent-region-or-paragraph</span> (start end)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"r"</span>)
(<span style="color: #0000ff;">if</span> mark-active
(cperl-indent-region start end)
(<span style="color: #0000ff;">save-excursion</span>
(mark-paragraph)
(cperl-indent-region (point) (mark t))
)))
</pre>
</div>
<p>
and hook them into cperl
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook
<span style="color: #ff00ff;">'cperl-mode-hook</span>
(<span style="color: #0000ff;">function</span>
(<span style="color: #0000ff;">lambda</span>()
(make-variable-buffer-local <span style="color: #ff00ff;">'perl-error-fontified</span>)
(make-variable-buffer-local <span style="color: #ff00ff;">'perl-error-start</span>)
(make-variable-buffer-local <span style="color: #ff00ff;">'perl-error-end</span>)
(make-variable-buffer-local <span style="color: #ff00ff;">'perl-old-switches</span>)
(make-variable-buffer-local <span style="color: #ff00ff;">'perl-old-parameters</span>)
(local-set-key <span style="color: #ff0000;">"\C-hF"</span> <span style="color: #ff00ff;">'cperl-info-on-current-command</span>)
(local-set-key <span style="color: #ff0000;">"\C-hf"</span> <span style="color: #ff00ff;">'describe-function</span>)
(local-set-key <span style="color: #ff0000;">"\C-hV"</span> <span style="color: #ff00ff;">'cperl-get-help</span>)
(local-set-key <span style="color: #ff0000;">"\C-hv"</span> <span style="color: #ff00ff;">'describe-variable</span>)
(local-set-key <span style="color: #ff0000;">"\C-cr"</span> <span style="color: #ff00ff;">'perl-run</span>)
(local-set-key <span style="color: #ff0000;">"\C-ck"</span> <span style="color: #ff00ff;">'perl-kill</span>)
(local-set-key <span style="color: #ff0000;">"\C-c#"</span> <span style="color: #ff00ff;">'perl-next-error</span>)
(local-set-key <span style="color: #ff0000;">"\M-\C-q"</span> <span style="color: #ff00ff;">'own-cperl-indent-region-or-paragraph</span>)
(<span style="color: #0000ff;">setq</span> mode-name <span style="color: #ff0000;">"PL"</span>)
)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org3bbbe92" class="outline-4">
<h4 id="org3bbbe92"><span class="section-number-4">6.1.6</span> Paredit for lisp only</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-6">
<p>
13.11.2018: disabled in exchange for smartparens, which see
</p>
<p>
I use paredit in lisp a lot, and I'm mostly happy with the defaults.
</p>
<p>
(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
</p>
<p>
;; However, I use it with lisp dialects only
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1)))
</p>
<p>
;; sometimes I need to be able to turn it off fast:
(defalias 'pe 'paredit-mode)
</p>
<p>
(eval-after-load 'paredit
'(progn
;; force my own bindings for those
(define-key paredit-mode-map (kbd "C-d") nil)
(define-key paredit-mode-map (kbd "&lt;M-up&gt;") nil)
(define-key paredit-mode-map (kbd "&lt;M-down&gt;") nil)))
</p>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org5daac4e" class="outline-4">
<h4 id="org5daac4e"><span class="section-number-4">6.1.7</span> Smart Parens</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-7">
<p>
I'm trying to migrate to smart-parens, since it supports all of
paredit but can do more
</p>
<p>
Also look at:
<a href="https://github.com/Fuco1/.emacs.d/blob/master/files/smartparens.el">https://github.com/Fuco1/.emacs.d/blob/master/files/smartparens.el</a>
<a href="https://github.com/Fuco1/smartparens/wiki">https://github.com/Fuco1/smartparens/wiki</a>
<a href="https://ebzzry.io/en/emacs-pairs/">https://ebzzry.io/en/emacs-pairs/</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'smartparens-config</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'cl</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-disable-par-and-pair</span>()
<span style="color: #cd6600;">"Disables Paredit and Electric-Pair-Mode if currently active.</span>
<span style="color: #cd6600;">Used when enabling smartparens-mode."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">when</span> electric-pair-mode
(electric-pair-mode))
(<span style="color: #0000ff;">when</span> (fboundp <span style="color: #ff00ff;">'pparedit-mode</span>)
(<span style="color: #0000ff;">when</span> paredit-mode
(disable-paredit-mode))))
</pre>
</div>
<p>
enable sp in minibuffer as well
maybe, see: <a href="https://github.com/Fuco1/smartparens/issues/33">https://github.com/Fuco1/smartparens/issues/33</a>:
(sp-local-pair 'minibuffer-inactive-mode "'" nil :actions nil)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> sp-ignore-modes-list
(delete <span style="color: #ff00ff;">'minibuffer-inactive-mode</span> sp-ignore-modes-list))
</pre>
</div>
<p>
automatically enable where needed
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-something-to-mode-hooks
2020-09-04 18:47:46 +02:00
'(rust emacs-lisp ielm lisp lisp-interaction scheme slime-repl ) <span style="color: #ff00ff;">'smartparens-mode</span>)
2020-09-02 20:44:21 +02:00
</pre>
</div>
<p>
also in some select prog modes
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-something-to-mode-hooks
'(perl ruby c c++ shell-script makefile config-general) <span style="color: #ff00ff;">'smartparens-mode</span>)
</pre>
</div>
<p>
I use my own lisp comment tool until sp#942 is fixed
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-lisp-comment</span> ()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (looking-at <span style="color: #ff0000;">"\s*\("</span>))
(self-insert-command 1)
(<span style="color: #0000ff;">let</span> ((beg (point)))
(forward-list 1)
(<span style="color: #0000ff;">when</span> (looking-at <span style="color: #ff0000;">"\s*\)"</span>)
(insert <span style="color: #ff0000;">"\n"</span>))
(comment-region beg (point))
(indent-for-tab-command)
(goto-char beg))))
(eval-after-load <span style="color: #ff00ff;">'smartparens</span>
'(<span style="color: #0000ff;">progn</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">hydra via https://github.com/lunaryorn/old-emacs-configuration/blob/master/init.el</span>
(<span style="color: #0000ff;">defhydra</span> hydra-smartparens (<span style="color: #8a2be2;">:hint</span> nil)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">Sexps [quit with _q_, reach this hydra with 'C-x (']</span>
<span style="color: #cd6600;">^Nav^ ^Barf/Slurp^ ^Depth^</span>
<span style="color: #cd6600;">^---^-----------------------^----------^---------------------------^-----^-----------------</span>
<span style="color: #cd6600;">_f_: forward (C-M-right) _&#8594;_: slurp forward (C-right) _R_: splice</span>
<span style="color: #cd6600;">_b_: backward (C-M-left) _&#8592;_: barf forward (C-left) _r_: raise</span>
<span style="color: #cd6600;">_u_: backward &#8593; _C-&lt;right&gt;_: slurp backward _&#8593;_: raise backward</span>
<span style="color: #cd6600;">_d_: forward &#8595; (C-M-down) _C-&lt;left&gt;_: barf backward _&#8595;_: raise forward</span>
<span style="color: #cd6600;">_p_: backward &#8595;</span>
<span style="color: #cd6600;">_n_: forward &#8593; (C-M-up)</span>
<span style="color: #cd6600;">^Kill^ ^Misc^ ^Wrap^</span>
<span style="color: #cd6600;">^----^-----------^----^-----------------------^----^------------------</span>
<span style="color: #cd6600;">_w_: copy _j_: join _(_: wrap with ( )</span>
<span style="color: #cd6600;">_k_: kill (C-k) _s_: split _{_: wrap with { }</span>
<span style="color: #cd6600;">^^ _t_: transpose _'_: wrap with ' '</span>
<span style="color: #cd6600;">^^ _c_: convolute _\"_: wrap with \" \"</span>
<span style="color: #cd6600;">^^ _i_: indent defun</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"q"</span> nil)
<span style="color: #006400;">;; </span><span style="color: #006400;">Wrapping</span>
(<span style="color: #ff0000;">"("</span> (<span style="color: #0000ff;">lambda</span> (_) (<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>) (sp-wrap-with-pair <span style="color: #ff0000;">"("</span>)))
(<span style="color: #ff0000;">"{"</span> (<span style="color: #0000ff;">lambda</span> (_) (<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>) (sp-wrap-with-pair <span style="color: #ff0000;">"{"</span>)))
(<span style="color: #ff0000;">"'"</span> (<span style="color: #0000ff;">lambda</span> (_) (<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>) (sp-wrap-with-pair <span style="color: #ff0000;">"'"</span>)))
(<span style="color: #ff0000;">"\""</span> (<span style="color: #0000ff;">lambda</span> (_) (<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>) (sp-wrap-with-pair <span style="color: #ff0000;">"\""</span>)))
<span style="color: #006400;">;; </span><span style="color: #006400;">Navigation</span>
(<span style="color: #ff0000;">"f"</span> sp-forward-sexp )
(<span style="color: #ff0000;">"b"</span> sp-backward-sexp)
(<span style="color: #ff0000;">"u"</span> sp-backward-up-sexp)
(<span style="color: #ff0000;">"d"</span> sp-down-sexp)
(<span style="color: #ff0000;">"p"</span> sp-backward-down-sexp)
(<span style="color: #ff0000;">"n"</span> sp-up-sexp)
<span style="color: #006400;">;; </span><span style="color: #006400;">Kill/copy</span>
(<span style="color: #ff0000;">"w"</span> sp-copy-sexp)
(<span style="color: #ff0000;">"k"</span> sp-kill-sexp)
<span style="color: #006400;">;; </span><span style="color: #006400;">Misc</span>
(<span style="color: #ff0000;">"t"</span> sp-transpose-sexp)
(<span style="color: #ff0000;">"j"</span> sp-join-sexp)
(<span style="color: #ff0000;">"s"</span> sp-split-sexp)
(<span style="color: #ff0000;">"c"</span> sp-convolute-sexp)
(<span style="color: #ff0000;">"i"</span> sp-indent-defun)
<span style="color: #006400;">;; </span><span style="color: #006400;">Depth changing</span>
(<span style="color: #ff0000;">"R"</span> sp-splice-sexp)
(<span style="color: #ff0000;">"r"</span> sp-splice-sexp-killing-around)
(<span style="color: #ff0000;">"&lt;up&gt;"</span> sp-splice-sexp-killing-backward)
(<span style="color: #ff0000;">"&lt;down&gt;"</span> sp-splice-sexp-killing-forward)
<span style="color: #006400;">;; </span><span style="color: #006400;">Barfing/slurping</span>
(<span style="color: #ff0000;">"&lt;left&gt;"</span> sp-forward-slurp-sexp)
(<span style="color: #ff0000;">"&lt;right&gt;"</span> sp-forward-barf-sexp)
(<span style="color: #ff0000;">"C-&lt;left&gt;"</span> sp-backward-barf-sexp)
(<span style="color: #ff0000;">"C-&lt;right&gt;"</span> sp-backward-slurp-sexp))
<span style="color: #006400;">;; </span><span style="color: #006400;">via https://ebzzry.io/en/emacs-pairs/:</span>
(<span style="color: #0000ff;">defmacro</span> <span style="color: #9932cc;">def-pairs</span> (pairs)
<span style="color: #cd6600;">"Define functions for pairing. PAIRS is an alist of (NAME . STRING)</span>
<span style="color: #cd6600;">conses, where NAME is the function name that will be created and</span>
<span style="color: #cd6600;">STRING is a single-character string that marks the opening character.</span>
<span style="color: #cd6600;"> (def-pairs ((paren . \"(\")</span>
<span style="color: #cd6600;"> (bracket . \"[\"))</span>
<span style="color: #cd6600;">defines the functions WRAP-WITH-PAREN and WRAP-WITH-BRACKET,</span>
<span style="color: #cd6600;">respectively."</span>
`(<span style="color: #0000ff;">progn</span>
,@(<span style="color: #0000ff;">loop</span> for (key . val) in pairs
collect
`(<span style="color: #0000ff;">defun</span> ,(read (concat
<span style="color: #ff0000;">"wrap-with-"</span>
(prin1-to-string key)
<span style="color: #ff0000;">"s"</span>))
(<span style="color: #483d8b;">&amp;optional</span> arg)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"p"</span>)
(sp-wrap-with-pair ,val)))))
(<span style="color: #0000ff;">def-pairs</span> ((paren . <span style="color: #ff0000;">"("</span>)
(bracket . <span style="color: #ff0000;">"["</span>)
(brace . <span style="color: #ff0000;">"{"</span>)
(single-quote . <span style="color: #ff0000;">"'"</span>)
(double-quote . <span style="color: #ff0000;">"\""</span>)
(back-quote . <span style="color: #ff0000;">"`"</span>)))
<span style="color: #006400;">;;</span><span style="color: #006400;">(add-hook 'smartparens-enabled-hook #'tvd-disable-par-and-pair)</span>
<span style="color: #006400;">;;</span><span style="color: #006400;">(add-hook 'smartparens-enabled-hook #'turn-on-smartparens-strict-mode)</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">auto wrapping w/o region</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c ("</span>) <span style="color: #ff00ff;">'wrap-with-parens</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c ["</span>) <span style="color: #ff00ff;">'wrap-with-brackets</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c {"</span>) <span style="color: #ff00ff;">'wrap-with-braces</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c '"</span>) <span style="color: #ff00ff;">'wrap-with-single-quotes</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c \""</span>) <span style="color: #ff00ff;">'wrap-with-double-quotes</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c `"</span>) <span style="color: #ff00ff;">'wrap-with-back-quotes</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">modification</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x ("</span>) <span style="color: #ff00ff;">'hydra-smartparens</span>/body)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-k"</span>) <span style="color: #ff00ff;">'sp-kill-hybrid-sexp</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-&lt;left&gt;"</span>) <span style="color: #ff00ff;">'sp-forward-slurp-sexp</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-&lt;right&gt;"</span>) <span style="color: #ff00ff;">'sp-forward-barf-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">movement</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">Also Check: https://github.com/Fuco1/smartparens/wiki/Working-with-expressions</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">(look for "quick summary for each navigation function")</span>
<span style="color: #006400;">;;</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">Jump after the next balanced expression. If inside one and</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">there is no forward exp., jump after its closing pair.</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;right&gt;"</span>) <span style="color: #ff00ff;">'sp-forward-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">Jump before the previous balanced expression. If inside one</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">and there is no previous exp., jump before its opening pair.</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;left&gt;"</span>) <span style="color: #ff00ff;">'sp-backward-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">Jump up one level from the current balanced expression. This</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">means skipping all the enclosed expressions within this and</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">then jumping after the closing pair.</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;up&gt;"</span>) <span style="color: #ff00ff;">'sp-up-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">Jump after the opening pair of next balanced expression. This</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">effectively descends one level down in the "expression</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">hierarchy". If there is no expression to descend to, jump</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">after current expression's opening pair. This can be used to</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">quickly navigate to the beginning of current balanced</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">expression.</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;down&gt;"</span>) <span style="color: #ff00ff;">'sp-down-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">Jump to the beginning of following balanced expression. If</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">there is no following expression on the current level, jump</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">one level up backward, effectively doing sp-backward-up-sexp.</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-S-&lt;left&gt;"</span>) <span style="color: #ff00ff;">'sp-next-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">Jump to the end of the previous balanced expression. If there</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">is no previous expression on the current level, jupm one level</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">up forward, effectively doing sp-up-sexp.</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-S-&lt;right&gt;"</span>) <span style="color: #ff00ff;">'sp-previous-sexp</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">comment the whole sexp</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">";"</span>) <span style="color: #ff00ff;">'tvd-lisp-comment</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">replace my global setting</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">/</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #006400;">/: fhceck/fix M&lt;up+down&gt;!</span>
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-&lt;right&gt;"</span>) <span style="color: #ff00ff;">'sp-forward-symbol</span>)
(define-key smartparens-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-&lt;left&gt;"</span>) <span style="color: #ff00ff;">'sp-backward-symbol</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org793f9f5" class="outline-4">
<h4 id="org793f9f5"><span class="section-number-4">6.1.8</span> ETAGS</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-1-8">
<p>
I use ETAGS for some projects. With etags I can easily jump to the
definition of a function, struct or whatever across files and
directories.
</p>
<p>
manually generate the tags file:
/usr/bin/ctags-exuberant -e *.c &#x2026;
visit-tags-file ("TAGS" whereever ctags run)
</p>
<p>
then load TAGS with visit-tags-table
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'etags-select</span>)
</pre>
</div>
<p>
generate TAGS and load it
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">etags-create</span> (dir-name)
<span style="color: #cd6600;">"Create tags file."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"DDirectory: "</span>)
(<span style="color: #0000ff;">let*</span> ((ctags <span style="color: #ff0000;">"/usr/bin/ctags-exuberant"</span>)
(odir (directory-file-name dir-name))
(ofile (concat odir <span style="color: #ff0000;">"/TAGS"</span>))
(langs <span style="color: #ff0000;">"lisp,python,perl,c,c++,shell"</span>)
(shell-command
(format <span style="color: #ff0000;">"%s -f %s -e -R --languages=%s %s"</span> ctags ofile langs odir))
(visit-tags-table ofile))))
</pre>
</div>
<p>
ALT<sub>R</sub> + e (equals on de keyboard € sign): jump to tag source
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#8364;"</span>) <span style="color: #ff00ff;">'etags-select-find-tag-at-point</span>) <span style="color: #006400;">; </span><span style="color: #006400;">alt-right + e: jump to tag definition</span>
</pre>
</div>
<p>
Use ido to list tags, but then select via etags-select (best of both worlds!)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">etags-find</span> ()
<span style="color: #cd6600;">"Find a tag using ido"</span>
(<span style="color: #0000ff;">interactive</span>)
(tags-completion-table)
(<span style="color: #0000ff;">let</span> (tag-names)
(mapatoms (<span style="color: #0000ff;">lambda</span> (x)
(<span style="color: #0000ff;">push</span> (prin1-to-string x t) tag-names))
tags-completion-table)
(etags-select-find (ido-completing-read <span style="color: #ff0000;">"Tag: "</span> tag-names))))
</pre>
</div>
<p>
some handy aliases
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ec</span> <span style="color: #ff00ff;">'etags-create</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ef</span> <span style="color: #ff00ff;">'etags-find</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org399565c" class="outline-4">
<h4 id="org399565c"><span class="section-number-4">6.1.9</span> Go Lang</h4>
<div class="outline-text-4" id="text-6-1-9">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'go-mode</span> <span style="color: #ff0000;">"go-mode"</span> nil t)
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.go\\'"</span> . go-mode))
</pre>
2020-09-02 20:44:21 +02:00
</div>
2021-05-01 13:15:16 +02:00
<hr />
</div>
</div>
</div>
<div id="outline-container-org7f68b34" class="outline-3">
<h3 id="org7f68b34"><span class="section-number-3">6.2</span> Text Modes</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-6-2">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org87df60f" class="outline-4">
<h4 id="org87df60f"><span class="section-number-4">6.2.1</span> sgml</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-1">
<p>
Used for XML and the likes.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> sgml-set-face t)
(<span style="color: #0000ff;">setq</span> sgml-balanced-tag-edit t)
(<span style="color: #0000ff;">setq</span> sgml-omittag-transparent nil)
(<span style="color: #0000ff;">setq</span> sgml-auto-insert-required-elements t)
(<span style="color: #0000ff;">setq</span> sgml-markup-faces
'((start-tag . font-lock-function-name-face)
(end-tag . font-lock-function-name-face)
(comment . font-lock-comment-face)
(pi . font-lock-other-type-face)
(sgml . font-lock-variable-name-face)
(doctype . font-lock-type-face)
(entity . font-lock-string-face)
(shortref . font-lock-keyword-face)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgd81b540" class="outline-4">
<h4 id="orgd81b540"><span class="section-number-4">6.2.2</span> web-mode (JS, HTML, CSS combined)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-2">
<p>
Web development is shit. Tech involved is a mess, and in most cases
intermixed. web-mode provides a great fix for this: it handles
HTML, CSS and Javascript in the same buffer very well.
</p>
<p>
See: <a href="http://web-mode.org/">web-mode.org</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'web-mode</span>)
</pre>
</div>
<p>
associate with the usual suspects
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.phtml\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.tpl\\.php\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.[agj]sp\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.as[cp]x\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.erb\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.mustache\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.djhtml\\'"</span> . web-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.html?\\'"</span> . web-mode))
</pre>
</div>
<p>
configure web mode
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-web-mode-hook</span> ()
<span style="color: #cd6600;">"Hooks for Web mode."</span>
(<span style="color: #0000ff;">setq</span> web-mode-markup-indent-offset 2)
(<span style="color: #0000ff;">setq</span> web-mode-css-indent-offset 2)
(<span style="color: #0000ff;">setq</span> web-mode-code-indent-offset 2)
(<span style="color: #0000ff;">setq</span> web-mode-style-padding 1)
(<span style="color: #0000ff;">setq</span> web-mode-script-padding 1)
(<span style="color: #0000ff;">setq</span> web-mode-block-padding 0)
(<span style="color: #0000ff;">setq</span> web-mode-enable-auto-pairing t)
(<span style="color: #0000ff;">setq</span> web-mode-enable-auto-expanding t))
(add-hook <span style="color: #ff00ff;">'web-mode-hook</span> <span style="color: #ff00ff;">'tvd-web-mode-hook</span>)
</pre>
</div>
<p>
some handy html code inserters
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">html-insert-p</span>()
(<span style="color: #0000ff;">interactive</span>)
(web-mode-element-wrap <span style="color: #ff0000;">"p"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">html-insert-li</span>()
(<span style="color: #0000ff;">interactive</span>)
(web-mode-element-wrap <span style="color: #ff0000;">"li"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">html-insert-ul</span>()
(<span style="color: #0000ff;">interactive</span>)
(web-mode-element-wrap <span style="color: #ff0000;">"ul"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">html-insert-b</span>()
(<span style="color: #0000ff;">interactive</span>)
(web-mode-element-wrap <span style="color: #ff0000;">"b"</span>))
</pre>
</div>
<p>
convert a text list into a html list.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">html-listify</span> (beg end)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"r"</span>)
(<span style="color: #0000ff;">save-excursion</span>
(<span style="color: #0000ff;">let*</span> ((lines (split-string (buffer-substring beg end) <span style="color: #ff0000;">"\n"</span> t)))
(delete-region beg end)
(insert <span style="color: #ff0000;">"&lt;ul&gt;\n"</span>)
(<span style="color: #0000ff;">while</span> lines
(insert <span style="color: #ff0000;">" &lt;li&gt;"</span>)
(insert (<span style="color: #0000ff;">pop</span> lines))
(insert <span style="color: #ff0000;">"&lt;/li&gt;\n"</span>))
(insert <span style="color: #ff0000;">"&lt;/ul&gt;\n"</span>)
)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgdd5daf7" class="outline-4">
<h4 id="orgdd5daf7"><span class="section-number-4">6.2.3</span> Cisco Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-3">
<p>
Written by myself many years ago, but I'm still using it daily to
view and prepare cisco configs.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'cisco-mode</span> <span style="color: #ff0000;">"cisco-mode"</span> <span style="color: #cd6600;">"Major mode for CISCO configs"</span> t)
(<span style="color: #0000ff;">setq</span> auto-mode-alist
(append '((<span style="color: #ff0000;">"\\.</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">cfg</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">$"</span> . cisco-mode))
auto-mode-alist))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgfa4df1a" class="outline-4">
<h4 id="orgfa4df1a"><span class="section-number-4">6.2.4</span> Markdown</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-4">
<p>
I rarely use markdown, but sometimes I stumble upon such a file and
like to view it with emacs without rendering.
Source: <a href="http://jblevins.org/projects/markdown-mode/">jblevins.org</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'markdown-mode</span> <span style="color: #ff0000;">"markdown-mode"</span>
<span style="color: #cd6600;">"Major mode for editing Markdown files"</span> t)
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.text\\'"</span> . markdown-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.markdown\\'"</span> . markdown-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.md\\'"</span> . markdown-mode))
</pre>
</div>
<p>
parens and quotes constraints check on save
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'markdown-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">when</span> buffer-file-name
(add-hook <span style="color: #ff00ff;">'after-save-hook</span>
<span style="color: #ff00ff;">'check-parens</span>
nil t))
(modify-syntax-entry ?\" <span style="color: #ff0000;">"\""</span> markdown-mode-syntax-table)
))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgabc03ca" class="outline-4">
<h4 id="orgabc03ca"><span class="section-number-4">6.2.5</span> POD mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-5">
<p>
I LOVE POD! POD is the documentation format of perl and there's a
solid toolset available for it. I use it to write documentation and
manual pages. It's much more powerfull than lame markdown and you
can even program great tools yourself around POD (like I did with
PodWiki years ago!)
</p>
<p>
Although cperl mode already has some POD support, pod mode is way
better.
</p>
<p>
Source: <a href="https://github.com/renormalist/emacs-pod-mode">emacs-pod-mode</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'pod-mode</span>)
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.pod$"</span> . pod-mode))
(add-hook <span style="color: #ff00ff;">'pod-mode-hook</span> <span style="color: #ff00ff;">'font-lock-mode</span>)
</pre>
</div>
<p>
using expand-region: apply pod entity formatting to word at point.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outline-emphasize</span>(CHAR)
<span style="color: #cd6600;">"expand once if no region and apply emphasize CHAR"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">unless</span> (use-region-p)
(er/expand-region 1))
(<span style="color: #0000ff;">save-excursion</span>
(goto-char (region-beginning))
(insert (format <span style="color: #ff0000;">"%c&lt;"</span> CHAR))
(goto-char (region-end))
(insert <span style="color: #ff0000;">"&gt;"</span>)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">pod-bold</span>()
<span style="color: #cd6600;">"bold text in outline mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-outline-emphasize ?B))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">pod-italic</span>()
<span style="color: #cd6600;">"italic text in outline mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-outline-emphasize ?I))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">pod-code</span>()
<span style="color: #cd6600;">"verbatim text in outline mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-outline-emphasize ?C))
</pre>
</div>
<p>
enhance abbrevs and jump into expanded area to the
$ character (if it exists), which it also removes
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-abbrev-pos 0)
(advice-add <span style="color: #ff00ff;">'expand-abbrev</span> <span style="color: #8a2be2;">:before</span>
'(<span style="color: #0000ff;">lambda</span> () (<span style="color: #0000ff;">setq</span> tvd-abbrev-pos (point))))
(advice-add <span style="color: #ff00ff;">'expand-abbrev</span> <span style="color: #8a2be2;">:after</span>
'(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">ignore-errors</span>
(<span style="color: #0000ff;">when</span> (re-search-backward <span style="color: #ff0000;">"\\$"</span> (- tvd-abbrev-pos 0))
(delete-char 1)))))
</pre>
</div>
<p>
pod mode config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'pod-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
<span style="color: #006400;">;; </span><span style="color: #006400;">tune syntax table</span>
(modify-syntax-entry ?= <span style="color: #ff0000;">"w"</span> pod-mode-syntax-table)
<span style="color: #006400;">;; </span><span style="color: #006400;">POD contains headers and I'm used to outlining if there are headers</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">so, enable outlining</span>
(<span style="color: #0000ff;">setq</span> outline-heading-alist '((<span style="color: #ff0000;">"=head1"</span> . 1)
(<span style="color: #ff0000;">"=head2"</span> . 2)
(<span style="color: #ff0000;">"=head3"</span> . 3)
(<span style="color: #ff0000;">"=head4"</span> . 4)
(<span style="color: #ff0000;">"=over"</span> . 5)
(<span style="color: #ff0000;">"=item"</span> . 6)
(<span style="color: #ff0000;">"=begin"</span> . 5)
(<span style="color: #ff0000;">"=pod"</span> . 5)
))
<span style="color: #006400;">;; </span><span style="color: #006400;">outline alone, however, works well</span>
(outline-minor-mode)
<span style="color: #006400;">;; </span><span style="color: #006400;">my own abbrevs for POD using mode-specific abbrev table</span>
(define-abbrev-table <span style="color: #ff00ff;">'pod-mode-abbrev-table</span> '(
(<span style="color: #ff0000;">"=o"</span> <span style="color: #ff0000;">"=over\n\n=item *$\n\n=back\n\n"</span>)
(<span style="color: #ff0000;">"=i"</span> <span style="color: #ff0000;">"=item "</span>)
(<span style="color: #ff0000;">"=h1"</span> <span style="color: #ff0000;">"=head1 "</span>)
(<span style="color: #ff0000;">"=h2"</span> <span style="color: #ff0000;">"=head2 "</span>)
(<span style="color: #ff0000;">"=h3"</span> <span style="color: #ff0000;">"=head3 "</span>)
(<span style="color: #ff0000;">"=h4"</span> <span style="color: #ff0000;">"=head4 "</span>)
(<span style="color: #ff0000;">"=c"</span> <span style="color: #ff0000;">"=cut"</span>)
(<span style="color: #ff0000;">"=b"</span> <span style="color: #ff0000;">"=begin"</span>)
(<span style="color: #ff0000;">"=e"</span> <span style="color: #ff0000;">"=end"</span>)
(<span style="color: #ff0000;">"b"</span> <span style="color: #ff0000;">"B&lt;$&gt;"</span>)
(<span style="color: #ff0000;">"c"</span> <span style="color: #ff0000;">"C&lt;$&gt;"</span>)
(<span style="color: #ff0000;">"l"</span> <span style="color: #ff0000;">"L&lt;$&gt;"</span>)
(<span style="color: #ff0000;">"i"</span> <span style="color: #ff0000;">"I&lt;$&gt;"</span>)
(<span style="color: #ff0000;">"e"</span> <span style="color: #ff0000;">"E&lt;$&gt;"</span>)
(<span style="color: #ff0000;">"f"</span> <span style="color: #ff0000;">"F&lt;$&gt;"</span>))
<span style="color: #cd6600;">"POD mode abbreviations, see .emacs"</span>)
(abbrev-table-put pod-mode-abbrev-table <span style="color: #8a2be2;">:case-fixed</span> t)
(abbrev-table-put pod-mode-abbrev-table <span style="color: #8a2be2;">:system</span> t)
<span style="color: #006400;">;; </span><span style="color: #006400;">enable abbreviations</span>
(<span style="color: #0000ff;">setq</span> local-abbrev-table pod-mode-abbrev-table)
(abbrev-mode 1)
<span style="color: #006400;">;; </span><span style="color: #006400;">POD easy formatting</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c b"</span>) <span style="color: #ff00ff;">'pod-bold</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c /"</span>) <span style="color: #ff00ff;">'pod-italic</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c c"</span>) <span style="color: #ff00ff;">'pod-code</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org21f980b" class="outline-4">
<h4 id="org21f980b"><span class="section-number-4">6.2.6</span> conf-mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-6">
<p>
conf-mode annoyingly overwrites the global keybinding C-c C-c with
some of its internal crab. So, force it to use my own defun. Also,
while we're at it, disable electric indent, it's annoying in
configs. Applies for derivates as well.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-disarm-conf-mode</span>()
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-c"</span>) <span style="color: #ff00ff;">'comment-or-uncomment-region-or-line</span>)
(electric-indent-local-mode 0))
(add-something-to-mode-hooks '(conf cisco fundamental conf-space pod) <span style="color: #ff00ff;">'tvd-disarm-conf-mode</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb1c7026" class="outline-4">
<h4 id="orgb1c7026"><span class="section-number-4">6.2.7</span> Config::General mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-7">
2021-05-01 13:15:16 +02:00
</div><ol class="org-ol"><li><a id="orgbbd590c"></a>Config and doc<br /><div class="outline-text-5" id="text-6-2-7-1">
2020-09-02 20:44:21 +02:00
<p>
<a href="https://github.com/TLINDEN/config-general-mode">config-general-mode</a> (also on Melpa).
</p>
<p>
My own mode for <a href="http://search.cpan.org/dist/Config-General/">Config::General</a>
config files. Whenever I write some perl stuff, which needs a config file, I use
this module (and I do this a lot). Previously I used conf-mode or html-mode, but
both did not satisfy me. Now (as of 20170625) I solved this mess once and for all.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'config-general-mode</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'sh-script</span>)
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="org34a952a"></a>Convenicence Wrappers<br /><div class="outline-text-5" id="text-6-2-7-2">
2020-09-02 20:44:21 +02:00
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">config-general-completion-at-point</span> ()
<span style="color: #cd6600;">"Complete word at point using hippie-expand, if not on a comment."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">when</span> (looking-back <span style="color: #ff0000;">"[-%$_a-zA-Z0-9]"</span>)
(<span style="color: #0000ff;">unless</span> (<span style="color: #0000ff;">eq</span> (get-text-property (point) <span style="color: #ff00ff;">'face</span>) <span style="color: #ff00ff;">'font-lock-comment-face</span>)
(hippie-expand nil))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">config-general-do-electric-tab</span> ()
<span style="color: #cd6600;">"Enter a &lt;TAB&gt; or goto current indentation."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> (point) (line-end-position))
(indent-for-tab-command)
(back-to-indentation)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">config-general-tab-or-expand</span> ()
<span style="color: #cd6600;">"Do electric TAB or completion depending where point is.</span>
<span style="color: #cd6600;">This is just a convenience function, which can be mapped</span>
<span style="color: #cd6600;">to `</span><span style="color: #cd6600;">tab</span><span style="color: #cd6600;">' by the user. .Not in use by default."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">unless</span> (config-general-completion-at-point)
(config-general-do-electric-tab)))
</pre>
</div>
<p>
<i>FIXME</i>: Use this patched version for older emacsen and the default
for version which contain the patch (if any, ever).
</p>
<p>
The original function try-expand-dabbrev-all-buffers doesn't work
correctly, it ignores a buffer-local configuration of the variables
hippie-expand-only-buffers and hippie-expand-ignore-buffers. This
is the patched version of the function.
</p>
<p>
Bugreport: <a href="http://debbugs.gnu.org/cgi/bugreport.cgi?bug=27501">http://debbugs.gnu.org/cgi/bugreport.cgi?bug=27501</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">config-general--try-expand-dabbrev-all-buffers</span> (old)
<span style="color: #cd6600;">"Try to expand word \"dynamically\", searching all other buffers.</span>
<span style="color: #cd6600;">The argument OLD has to be nil the first call of this function, and t</span>
<span style="color: #cd6600;">for subsequent calls (for further possible expansions of the same</span>
<span style="color: #cd6600;">string). It returns t if a new expansion is found, nil otherwise."</span>
(<span style="color: #0000ff;">let</span> ((expansion ())
(buf (current-buffer))
(orig-case-fold-search case-fold-search)
(heib hippie-expand-ignore-buffers)
(heob hippie-expand-only-buffers)
)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> old)
(<span style="color: #0000ff;">progn</span>
(he-init-string (he-dabbrev-beg) (point))
(<span style="color: #0000ff;">setq</span> he-search-bufs (buffer-list))
(<span style="color: #0000ff;">setq</span> he-searched-n-bufs 0)
(set-marker he-search-loc 1 (<span style="color: #0000ff;">car</span> he-search-bufs))))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (equal he-search-string <span style="color: #ff0000;">""</span>))
(<span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">and</span> he-search-bufs
(<span style="color: #0000ff;">not</span> expansion)
(<span style="color: #0000ff;">or</span> (<span style="color: #0000ff;">not</span> hippie-expand-max-buffers)
(&lt; he-searched-n-bufs hippie-expand-max-buffers)))
(set-buffer (<span style="color: #0000ff;">car</span> he-search-bufs))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">and</span> (<span style="color: #0000ff;">not</span> (<span style="color: #0000ff;">eq</span> (current-buffer) buf))
(<span style="color: #0000ff;">if</span> heob
(he-buffer-member heob)
(<span style="color: #0000ff;">not</span> (he-buffer-member heib))))
(<span style="color: #0000ff;">save-excursion</span>
(<span style="color: #0000ff;">save-restriction</span>
(<span style="color: #0000ff;">if</span> hippie-expand-no-restriction
(widen))
(goto-char he-search-loc)
(<span style="color: #0000ff;">setq</span> expansion
(<span style="color: #0000ff;">let</span> ((case-fold-search orig-case-fold-search))
(he-dabbrev-search he-search-string nil)))
(set-marker he-search-loc (point))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> expansion)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">setq</span> he-search-bufs (<span style="color: #0000ff;">cdr</span> he-search-bufs))
(<span style="color: #0000ff;">setq</span> he-searched-n-bufs (1+ he-searched-n-bufs))
(set-marker he-search-loc 1 (<span style="color: #0000ff;">car</span> he-search-bufs))))))
(<span style="color: #0000ff;">setq</span> he-search-bufs (<span style="color: #0000ff;">cdr</span> he-search-bufs))
(set-marker he-search-loc 1 (<span style="color: #0000ff;">car</span> he-search-bufs)))))
(set-buffer buf)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> expansion)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> old (he-reset-string))
())
(<span style="color: #0000ff;">progn</span>
(he-substitute-string expansion t)
t))))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="orgbb4bd09"></a>Mode Hook<br /><div class="outline-text-5" id="text-6-2-7-3">
2020-09-02 20:44:21 +02:00
<p>
I use TAB for completion AND tab and outshine. Also, the mode
enables electric indent automatically, but I disabled it for
conf-mode (see tvd-disarm-conf-mode), therefore I re-enable it here
for config-general-mode (which inherits from conf-mode).
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'config-general-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(electric-indent-mode)
<span style="color: #006400;">;; </span><span style="color: #006400;">de-activate some senseless bindings</span>
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-c"</span>))
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-p"</span>))
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-u"</span>))
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-w"</span>))
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-x"</span>))
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c :"</span>))
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;tab&gt;"</span>) <span style="color: #ff00ff;">'config-general-tab-or-expand</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">from shell-script-mode, turn &lt;&lt; into here-doc</span>
(sh-electric-here-document-mode 1)
<span style="color: #006400;">;; </span><span style="color: #006400;">Inserting a brace or quote automatically inserts the matching pair</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">use smartparens now</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">(electric-pair-mode t)</span>
(<span style="color: #0000ff;">setq-local</span> hippie-expand-only-buffers '(config-general-mode))
<span style="color: #006400;">;; </span><span style="color: #006400;">configure order of expansion functions</span>
(<span style="color: #0000ff;">if</span> (version&lt; emacs-version <span style="color: #ff0000;">"25.1"</span>)
(<span style="color: #0000ff;">set</span> (make-local-variable <span style="color: #ff00ff;">'hippie-expand-try-functions-list</span>)
'(try-expand-dabbrev <span style="color: #006400;">;; </span><span style="color: #006400;">use patched version</span>
config-general--try-expand-dabbrev-all-buffers
try-complete-file-name-partially
try-complete-file-name))
(<span style="color: #0000ff;">set</span> (make-local-variable <span style="color: #ff00ff;">'hippie-expand-try-functions-list</span>)
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-complete-file-name-partially
try-complete-file-name)))
<span style="color: #006400;">;; </span><span style="color: #006400;">enable</span>
(add-hook <span style="color: #ff00ff;">'completion-at-point-functions</span> <span style="color: #ff00ff;">'config-general-completion-at-point</span>)
)
)
</pre>
</div>
<hr />
</div></li></ol>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb61f2e1" class="outline-4">
<h4 id="orgb61f2e1"><span class="section-number-4">6.2.8</span> Xmodmap Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-8">
<p>
the shortest mode ever, <a href="https://www.emacswiki.org/emacs/XModMapMode">via emacswiki</a>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">define-generic-mode</span> <span style="color: #ff00ff;">'xmodmap-mode</span>
'(?!)
'(<span style="color: #ff0000;">"add"</span> <span style="color: #ff0000;">"clear"</span> <span style="color: #ff0000;">"keycode"</span> <span style="color: #ff0000;">"keysym"</span> <span style="color: #ff0000;">"pointer"</span> <span style="color: #ff0000;">"remove"</span>)
'((<span style="color: #ff0000;">"[0-9]+"</span> . <span style="color: #ff00ff;">'font-lock-variable-name-face</span>))
'(<span style="color: #ff0000;">"[xX]modmap</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">rc</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">?\\'"</span>)
nil
<span style="color: #cd6600;">"Simple mode for xmodmap files."</span>)
</pre>
</div>
<p>
<a href="https://www.emacswiki.org/emacs/GenericMode">see GenericMode for more examples</a>.
</p>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org6f66f7d" class="outline-4">
<h4 id="org6f66f7d"><span class="section-number-4">6.2.9</span> MMM Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-9">
2021-05-01 13:15:16 +02:00
</div><ol class="org-ol"><li><a id="org74b43a4"></a>MMM configure:<br /><div class="outline-text-5" id="text-6-2-9-1">
2020-09-02 20:44:21 +02:00
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir <span style="color: #ff0000;">"/mmm-mode"</span>))
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'cl</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'mmm-auto</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'mmm-vars</span>)
(<span style="color: #0000ff;">setq</span> mmm-submode-decoration-level 2)
</pre>
</div>
<p>
<a href="https://github.com/purcell/mmm-mode">mmm-mode github</a>
see doc for class definition in var 'mmm-classes-alist
</p>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="org94eb3ab"></a>MMM config for POD mode<br /><div class="outline-text-5" id="text-6-2-9-2">
2020-09-02 20:44:21 +02:00
<div class="org-src-container">
<pre class="src src-emacs-lisp">(mmm-add-classes
'((html-pod
<span style="color: #8a2be2;">:submode</span> html-mode <span style="color: #006400;">;; </span><span style="color: #006400;">web-mode doesnt work this way!</span>
<span style="color: #8a2be2;">:delimiter-mode</span> nil
<span style="color: #8a2be2;">:front</span> <span style="color: #ff0000;">"=begin html"</span>
<span style="color: #8a2be2;">:back</span> <span style="color: #ff0000;">"=end html"</span>)))
(mmm-add-mode-ext-class <span style="color: #ff00ff;">'pod-mode</span> nil <span style="color: #ff00ff;">'html-pod</span>)
(add-hook <span style="color: #ff00ff;">'pod-mode-hook</span> <span style="color: #ff00ff;">'mmm-mode-on</span>)
</pre>
</div>
</div></li></ol>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgbf828c3" class="outline-4">
<h4 id="orgbf828c3"><span class="section-number-4">6.2.10</span> Yaml Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-2-10">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'yaml-mode</span>)
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.yml\\'"</span> . yaml-mode))
(add-to-list <span style="color: #ff00ff;">'auto-mode-alist</span> '(<span style="color: #ff0000;">"\\.j2\\'"</span> . yaml-mode))
(add-hook <span style="color: #ff00ff;">'yaml-mode-hook</span>
'(<span style="color: #0000ff;">lambda</span> ()
(define-key yaml-mode-map <span style="color: #ff0000;">"\C-m"</span> <span style="color: #ff00ff;">'newline-and-indent</span>)))
</pre>
</div>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org36b1524" class="outline-3">
<h3 id="org36b1524"><span class="section-number-3">6.3</span> Text Manupilation</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-6-3">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org37f300e" class="outline-4">
<h4 id="org37f300e"><span class="section-number-4">6.3.1</span> expand-region</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-1">
<p>
One of the best modes I ever discovered. Press C-= multiple times
to create a larger and larger region. I use C-0 (zero) because on a
german keyboard this is the same as C-= without pressing shift.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'expand-region</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-0"</span>) <span style="color: #ff00ff;">'er</span>/expand-region) <span style="color: #006400;">; </span><span style="color: #006400;">C-= without pressing shift on DE keyboard</span>
</pre>
</div>
<p>
related to ER:
</p>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orge98b15d" class="outline-4">
<h4 id="orge98b15d"><span class="section-number-4">6.3.2</span> Mark, Copy, Yank Things</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-2">
<p>
For a long time this stuff was located here in my emacs config. As
it grew larger and larger I decided to put it into its own mode:
mark-copy-yank-things-mode, which can be found on github these
days.
</p>
<p>
With this, you can quickly mark or copy or copy+yank things like
words, ip's, url's, lines or defun's with one key binding. I use
this permanently and couldn't live without it anymore.
</p>
<p>
A special feature is the copy+yanking, this is something vi offers:
go to a line, press yy, then p and the current line will be yanked
below. Prefix with a number and copy+yank more lines. This is
really cool and (in vi) often used. So, with this mode, I can use
it with emacs as well. For example, say you edit a configuration
file and added a complicated statement. Next you need to add
another very similar statement. Instead of entering it again, you
just hit &lt;C-c y y&gt; and the current line appears as a copy
below. Change the differences and you're done!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'mark-copy-yank-things-mode</span>)
(mark-copy-yank-things-global-mode)
</pre>
</div>
<p>
The mode has a rather impractical prefix since it's published on
github and therefore must be written in a way not to disturb other
modes. However, I myself need those simple prefixes:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key mark-copy-yank-things-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c"</span>) <span style="color: #ff00ff;">'mcyt-copy-map</span>)
(define-key mark-copy-yank-things-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-a"</span>) <span style="color: #ff00ff;">'mcyt-mark-map</span>)
</pre>
</div>
<p>
I use the default yank map
</p>
<p>
With this I put the last thing copied into a register 'c. I can
then later yank this using C-v anytime without browsing the
kill-ring if I kill things between yanking. So, C-v always inserts
the last copied thing, while C-y yanks the last thing killed, which
might be something else.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(advice-add <span style="color: #ff00ff;">'mcyt--copy-thing</span>
<span style="color: #8a2be2;">:after</span>
'(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args)
(<span style="color: #0000ff;">with-temp-buffer</span>
(yank)
(copy-to-register <span style="color: #ff00ff;">'c</span> (point-min) (point-max)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-insert-c-register</span> ()
(<span style="color: #0000ff;">interactive</span>)
(insert-register <span style="color: #ff00ff;">'c</span>))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-v"</span>) <span style="color: #ff00ff;">'tvd-insert-c-register</span>)
</pre>
</div>
<p>
copy a real number and convert it to german punctuation upon
yanking, so I can do some calculations in 'calculator, copy the
result NNN.NN and paste it into my online banking formular, where
it appears as NNN,NN.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-mcyt-copy-euro</span> (<span style="color: #483d8b;">&amp;optional</span> arg)
<span style="color: #cd6600;">"Copy euro at point into kill-ring and convert to german</span>
<span style="color: #cd6600;">punctuation"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>)
(mcyt--blink-and-copy-thing <span style="color: #ff00ff;">'mcyt-beginning-of-ip</span> <span style="color: #ff00ff;">'mcyt-end-of-ip</span> arg)
(<span style="color: #0000ff;">with-temp-buffer</span>
(yank)
(beginning-of-buffer)
(<span style="color: #0000ff;">while</span> (re-search-forward <span style="color: #ff0000;">"\\."</span> nil t)
(replace-match <span style="color: #ff0000;">","</span>))
(kill-region (point-min) (point-max))))
(eval-after-load <span style="color: #ff0000;">"mark-copy-yank-things-mode"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'mark-copy-yank-things-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> () <span style="color: #006400;">;; </span><span style="color: #006400;">g like [G]eld</span>
(define-key mcyt-copy-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"g"</span>) <span style="color: #ff00ff;">'tvd-mcyt-copy-euro</span>)))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org1e99d01" class="outline-4">
<h4 id="org1e99d01"><span class="section-number-4">6.3.3</span> change-inner</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-3">
<p>
I use change-inner with a prefix key and some wrappers around
mark-copy-yank-things-mode, which is related to change-inner
and expand-region.
</p>
<p>
<a href="https://github.com/magnars/change-inner.el">github source</a>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'change-inner</span>)
</pre>
</div>
<p>
first some functions:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci</span> (beg end <span style="color: #483d8b;">&amp;optional</span> ins)
<span style="color: #cd6600;">"change-inner simulator which works with symbols instead of strings.</span>
<span style="color: #cd6600;">BEG and END must be executable elisp symbols moving (point). Everything</span>
<span style="color: #cd6600;">in between will be killed. If INS is non-nil, it will be inserted then."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((B nil))
(funcall beg)
(<span style="color: #0000ff;">setq</span> B (point))
(funcall end)
(kill-region B (point))
(<span style="color: #0000ff;">when</span> ins
(insert ins))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-comment</span> ()
<span style="color: #cd6600;">"\"change inner\" a whole comment [block]."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-ci <span style="color: #ff00ff;">'mcyt-beginning-of-comment-block</span>
<span style="color: #ff00ff;">'mcyt-end-of-comment-block</span>
(format <span style="color: #ff0000;">"%s;# "</span> comment-start)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-quote</span> ()
<span style="color: #cd6600;">"\"change inner\" quoted text."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-ci <span style="color: #ff00ff;">'mcyt-beginning-of-quote</span>
<span style="color: #ff00ff;">'mcyt-end-of-quote</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-word</span> ()
<span style="color: #cd6600;">"\"change inner\" a word (like cw in vi)."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-ci <span style="color: #ff00ff;">'mcyt-beginning-of-symbol</span>
<span style="color: #ff00ff;">'mcyt-end-of-symbol</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-line</span> ()
<span style="color: #cd6600;">"\"change inner\" a whole line."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-ci <span style="color: #ff00ff;">'beginning-of-line</span>
<span style="color: #ff00ff;">'end-of-line</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-paragraph</span> ()
<span style="color: #cd6600;">"\"change inner\" a whole paragraph."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-ci <span style="color: #ff00ff;">'backward-paragraph</span>
<span style="color: #ff00ff;">'forward-paragraph</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-buffer</span> ()
<span style="color: #cd6600;">"\"change inner\" a whole buffer."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-ci <span style="color: #ff00ff;">'point-min</span>
<span style="color: #ff00ff;">'point-max</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ci-sexp</span> ()
<span style="color: #cd6600;">"\"change inner\" a whole sexp."</span>
(<span style="color: #0000ff;">interactive</span>)
(er/mark-inside-pairs)
(call-interactively <span style="color: #ff00ff;">'kill-region</span>))
</pre>
</div>
<p>
Define ALT<sub>R</sub> (AltGR) + i as my prefix command for change-inner stuff.
Since I use a german keyboard, this translates to →.
I'll refrence it here now as &lt;A-i &#x2026;&gt;
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-prefix-command <span style="color: #ff00ff;">'ci-map</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#8594;"</span>) <span style="color: #ff00ff;">'ci-map</span>)
</pre>
</div>
<p>
typing the prefix key twice calls the real change-inner
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#8594;"</span>) <span style="color: #ff00ff;">'change-inner</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-i&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"c"</span>) <span style="color: #ff00ff;">'tvd-ci-comment</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i c&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#162;"</span>) <span style="color: #ff00ff;">'tvd-ci-comment</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-c&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) <span style="color: #ff00ff;">'tvd-ci-quote</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i q&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"@"</span>) <span style="color: #ff00ff;">'tvd-ci-quote</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-q&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"w"</span>) <span style="color: #ff00ff;">'tvd-ci-word</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i w&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#322;"</span>) <span style="color: #ff00ff;">'tvd-ci-word</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-w&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"l"</span>) <span style="color: #ff00ff;">'tvd-ci-line</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i l&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"s"</span>) <span style="color: #ff00ff;">'tvd-ci-sexp</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i s&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#383;"</span>) <span style="color: #ff00ff;">'tvd-ci-sexp</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-s&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"p"</span>) <span style="color: #ff00ff;">'tvd-ci-paragraph</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i p&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#254;"</span>) <span style="color: #ff00ff;">'tvd-ci-paragraph</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-p&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"a"</span>) <span style="color: #ff00ff;">'tvd-ci-buffer</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i a&gt;</span>
(define-key ci-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&#230;"</span>) <span style="color: #ff00ff;">'tvd-ci-buffer</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">&lt;A-i A-a&gt;</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orga0d03c2" class="outline-4">
<h4 id="orga0d03c2"><span class="section-number-4">6.3.4</span> Rotate text</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-4">
<p>
This one is great as well, I use it to toggle flags and such stuff
in configs or code with just one key binding.
</p>
<p>
Source: <a href="http://nschum.de/src/emacs/rotate-text/">nschum.de</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'rotate-text</span> <span style="color: #ff0000;">"rotate-text"</span> nil t)
(autoload <span style="color: #ff00ff;">'rotate-text-backward</span> <span style="color: #ff0000;">"rotate-text"</span> nil t)
</pre>
</div>
<p>
my toggle list
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> rotate-text-words '((<span style="color: #ff0000;">"width"</span> <span style="color: #ff0000;">"height"</span>)
(<span style="color: #ff0000;">"left"</span> <span style="color: #ff0000;">"right"</span> <span style="color: #ff0000;">"top"</span> <span style="color: #ff0000;">"bottom"</span>)
(<span style="color: #ff0000;">"ja"</span> <span style="color: #ff0000;">"nein"</span>)
(<span style="color: #ff0000;">"off"</span> <span style="color: #ff0000;">"on"</span>)
(<span style="color: #ff0000;">"true"</span> <span style="color: #ff0000;">"false"</span>)
(<span style="color: #ff0000;">"nil"</span> <span style="color: #ff0000;">"t"</span>)
(<span style="color: #ff0000;">"yes"</span> <span style="color: #ff0000;">"no"</span>)))
</pre>
</div>
<p>
C-t normally used by transpose-chars, so, unbind it first
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-t"</span>))
</pre>
</div>
<p>
however, we cannot re-bind it globally since then it could not be
used in org-mode for org-todo (see below) <i>FIXME</i>: I only use the "t"
short command anymore, so C-t would be free now, wouldn't it?
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-something-to-mode-hooks
'(c c++ cperl vala web emacs-lisp python ruby)
'(<span style="color: #0000ff;">lambda</span> ()
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-t"</span>) <span style="color: #ff00ff;">'rotate-text</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org8cb32f9" class="outline-4">
<h4 id="org8cb32f9"><span class="section-number-4">6.3.5</span> Word wrapping</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-5">
<p>
same as word-wrap but without the fringe which I hate the most!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-something-to-mode-hooks '(tex text eww) <span style="color: #ff00ff;">'visual-line-mode</span>)
</pre>
</div>
<p>
however, it's required when coding, so enable it globally
overwritten by visual-line-mode above for specifics
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> word-wrap t)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgd5bbf4a" class="outline-4">
<h4 id="orgd5bbf4a"><span class="section-number-4">6.3.6</span> Viking Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-6">
<p>
Delete stuff fast. Press the key multiple times - delete more
things. Inspired by expand-region. Written by myself.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'viking-mode</span>)
(viking-global-mode)
(<span style="color: #0000ff;">setq</span> viking-greedy-kill nil)
(define-key viking-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-d"</span>) <span style="color: #ff00ff;">'viking-repeat-last-kill</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org2f83c5d" class="outline-4">
<h4 id="org2f83c5d"><span class="section-number-4">6.3.7</span> HTMLize</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-7">
<p>
extracted from debian package emacs-goodies-el-35.2+nmu1, since
there's no other source left. Generates a fontified html version of
the current buffer, however it looks.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'htmlize</span>)
(<span style="color: #0000ff;">setq</span> htmlize-output-type <span style="color: #ff0000;">"inline-css"</span>)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org7ebf55c" class="outline-4">
<h4 id="org7ebf55c"><span class="section-number-4">6.3.8</span> iEdit (inline edit multiple searches)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-3-8">
<p>
Edit all occurences of something at once. Great for re-factoring.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'iedit</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-e"</span>) <span style="color: #ff00ff;">'iedit-mode</span>)
</pre>
</div>
<p>
Keep buffer-undo-list as is while iedit is active, that is, as long
as I am inside iedit I can undo/redo current occurences. However,
if I leave iedit and issue the undo command, ALL changes made with
iedit are undone, whereas the default behaviour would be to go
through every change made iside iedit, which I hate.
</p>
<p>
iedit doesn't provide a customizable flag to configure it's undo
behavior, so, I modify it myself using defadvice.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-buffer-undo-list nil)
(advice-add <span style="color: #ff00ff;">'iedit-mode</span> <span style="color: #8a2be2;">:before</span> '(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args) <span style="color: #006400;">;; </span><span style="color: #006400;">save current</span>
(<span style="color: #0000ff;">setq</span> tvd-buffer-undo-list buffer-undo-list)))
(advice-add <span style="color: #ff00ff;">'iedit-mode</span> <span style="color: #8a2be2;">:after</span> '(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args) <span style="color: #006400;">;; </span><span style="color: #006400;">restore previously saved</span>
(<span style="color: #0000ff;">setq</span> buffer-undo-list tvd-buffer-undo-list)))
</pre>
</div>
<hr />
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgdac7240" class="outline-3">
<h3 id="orgdac7240"><span class="section-number-3">6.4</span> Interactives</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-6-4">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org1d14a75" class="outline-4">
<h4 id="org1d14a75"><span class="section-number-4">6.4.1</span> eShell stuff, or if interactive stuff is needed, use ansi-term</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-1">
<p>
I am a hardcore bash user, but from time to time eshell is good
enough. It's great when used remote when only sftp is supported.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'eshell</span>)
</pre>
</div>
<p>
fac'ifier
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defmacro</span> <span style="color: #9932cc;">with-face</span> (str <span style="color: #483d8b;">&amp;rest</span> properties)
`(propertize ,str <span style="color: #ff00ff;">'face</span> (list ,@properties)))
</pre>
</div>
<p>
custom prompt, which resembles my bash prompt
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">shk-eshell-prompt</span> ()
(<span style="color: #0000ff;">let</span> ((header-bg <span style="color: #ff0000;">"Azure"</span>))
(concat
(<span style="color: #0000ff;">with-face</span> <span style="color: #ff0000;">"\n"</span>)
(<span style="color: #0000ff;">with-face</span> (format-time-string
<span style="color: #ff0000;">"[%Y-%m-%d %H:%M] --- ["</span>
(current-time)) <span style="color: #8a2be2;">:background</span> header-bg <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"Black"</span>)
(<span style="color: #0000ff;">with-face</span> (concat (eshell/pwd) <span style="color: #ff0000;">""</span>) <span style="color: #8a2be2;">:background</span> header-bg <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"Blue"</span>)
(<span style="color: #0000ff;">with-face</span> <span style="color: #ff0000;">"] --- "</span> <span style="color: #8a2be2;">:background</span> header-bg <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"Black"</span>)
(<span style="color: #0000ff;">with-face</span> (<span style="color: #0000ff;">or</span>
(<span style="color: #0000ff;">ignore-errors</span> (format <span style="color: #ff0000;">"(%s)"</span> (vc-responsible-backend default-directory)))
<span style="color: #ff0000;">""</span>) <span style="color: #8a2be2;">:background</span> header-bg)
(<span style="color: #0000ff;">with-face</span> <span style="color: #ff0000;">"\n"</span> <span style="color: #8a2be2;">:background</span> header-bg)
(<span style="color: #0000ff;">with-face</span> user-login-name <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"blue"</span>)
<span style="color: #ff0000;">"@"</span>
(<span style="color: #0000ff;">with-face</span> <span style="color: #ff0000;">"localhost"</span> <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"blue"</span>)
(<span style="color: #0000ff;">if</span> (= (user-uid) 0)
(<span style="color: #0000ff;">with-face</span> <span style="color: #ff0000;">" #"</span> <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"red"</span>)
<span style="color: #ff0000;">" $"</span>)
<span style="color: #ff0000;">" "</span>)))
(<span style="color: #0000ff;">setq</span> eshell-prompt-function <span style="color: #ff00ff;">'shk-eshell-prompt</span>)
(<span style="color: #0000ff;">setq</span> eshell-highlight-prompt nil)
</pre>
</div>
<p>
I use my own virtual loggin target /dev/log, just redirect
command output to /dev/log and it will be saved to
the <b>LOG</b> buffer. &gt; inserts, &gt;&gt; appends
N.B: /dev/kill puts the stuff into the kill-ring.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">log-comment</span> ()
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*LOG*"</span>)
(insert (format <span style="color: #ff0000;">"# %s\n"</span> (time-stamp-string)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">log-insert</span> (string)
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*LOG*"</span>)
(delete-region (point-min) (point-max))
(log-comment)
(insert string)
(message <span style="color: #ff0000;">"wrote output to *LOG* buffer"</span>)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">log-append</span> (string)
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*LOG*"</span>)
(end-of-buffer)
(newline)
(log-comment)
(insert string)
(message <span style="color: #ff0000;">"wrote output to *LOG* buffer"</span>)))
</pre>
</div>
<p>
must return a defun which gets the stuff as ARG1
'mode is 'overwrite or 'append
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'eshell-virtual-targets</span> '(<span style="color: #ff0000;">"/dev/log"</span> (<span style="color: #0000ff;">lambda</span> (mode)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> mode <span style="color: #ff00ff;">'overwrite</span>)
<span style="color: #ff00ff;">'log-insert</span>
<span style="color: #ff00ff;">'log-append</span>))
t
))
</pre>
</div>
<p>
eshell config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"eshell"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'eshell-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(local-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-r"</span>)) <span style="color: #006400;">; </span><span style="color: #006400;">we're already using this for windresize</span>
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"tail"</span>)
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"top"</span>)
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"vi"</span>)
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"ssh"</span>)
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"tail"</span>)
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"mutt"</span>)
(add-to-list <span style="color: #ff00ff;">'eshell-visual-commands</span> <span style="color: #ff0000;">"note"</span>)
(setenv <span style="color: #ff0000;">"TERM"</span> <span style="color: #ff0000;">"xterm"</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-l"</span>) <span style="color: #ff00ff;">'eshell</span>/clear)
(define-key viking-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-d"</span>) nil) <span style="color: #006400;">;; </span><span style="color: #006400;">need to undef C-d first</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-d"</span>) <span style="color: #ff00ff;">'eshell</span>/x)
(<span style="color: #0000ff;">setq</span> mode-name <span style="color: #ff0000;">"ESH"</span>
eshell-hist-ignoredups t
eshell-history-size 5000
eshell-where-to-jump <span style="color: #ff00ff;">'begin</span>
eshell-review-quick-commands nil
eshell-smart-space-goes-to-end t
eshell-scroll-to-bottom-on-input <span style="color: #ff00ff;">'all</span>
eshell-error-if-no-glob t
eshell-save-history-on-exit t
eshell-prefer-lisp-functions t)))))
</pre>
</div>
<p>
exit and restore viking key binding afterwards
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell/x</span> (<span style="color: #483d8b;">&amp;rest</span> args)
(<span style="color: #0000ff;">interactive</span>)
(eshell-life-is-too-much)
(define-key viking-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-d"</span>) <span style="color: #ff00ff;">'viking-kill-thing-at-point</span>))
</pre>
</div>
<p>
open files in emacs, split the shell if not already splitted
open empty window if no file argument given.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell/emacs</span> (<span style="color: #483d8b;">&amp;rest</span> args)
<span style="color: #cd6600;">"Editor commands fired from eshell will be handled by emacs, which already runs anyway."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let*</span> ((framesize (frame-width))
(winsize (window-body-width)))
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> winsize framesize)
(split-window-horizontally))
(other-window 1)
(<span style="color: #0000ff;">if</span> (null args)
(bury-buffer)
(mapc #<span style="color: #ff00ff;">'find-file</span> (mapcar #<span style="color: #ff00ff;">'expand-file-name</span> (eshell-flatten-list (reverse args))))))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell/clear</span> ()
<span style="color: #cd6600;">"Better clear command than (recenter 0) which doesn't work as I</span>
<span style="color: #cd6600;">want. This version really removes the output of previous commands</span>
<span style="color: #cd6600;">and puts the shell to the beginning of a really (then) empty eshell</span>
<span style="color: #cd6600;">buffer. However, just to be sure that I do no accidentally clear</span>
<span style="color: #cd6600;">some shell output that might be useful in the future, it also</span>
<span style="color: #cd6600;">copies the cleared stuff into a backup buffer named</span>
<span style="color: #cd6600;">*eshell-log-buffer*, just in case."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((beg (point-min))
(end (point-max))
(savebuffer <span style="color: #ff0000;">"*eshell-log-buffer*"</span>)
(log (buffer-substring-no-properties (point-min) (point-max))))
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (get-buffer savebuffer))
(get-buffer-create savebuffer))
(<span style="color: #0000ff;">with-current-buffer</span> savebuffer
(goto-char (point-max))
(insert log))
(delete-region beg end)
(eshell-emit-prompt))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell/perldoc</span> (<span style="color: #483d8b;">&amp;rest</span> args)
<span style="color: #cd6600;">"Like `</span><span style="color: #cd6600;">eshell/man</span><span style="color: #cd6600;">', but invoke `</span><span style="color: #cd6600;">perldoc</span><span style="color: #cd6600;">'."</span>
(funcall <span style="color: #ff00ff;">'eshell</span>/perldoc (apply <span style="color: #ff00ff;">'eshell-flatten-and-stringify</span> args)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell/perldoc</span> (man-args)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"sPerldoc: "</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'man</span>)
(<span style="color: #0000ff;">let</span> ((manual-program <span style="color: #ff0000;">"perldoc"</span>))
(man man-args)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell-here</span> ()
<span style="color: #cd6600;">"Opens up a new shell in the directory associated with the</span>
<span style="color: #cd6600;">current buffer's file. The eshell is renamed to match that</span>
<span style="color: #cd6600;">directory to make multiple eshell windows easier."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let*</span> ((parent (<span style="color: #0000ff;">if</span> (buffer-file-name)
(file-name-directory (buffer-file-name))
default-directory))
(height (/ (window-total-height) 3))
(name (<span style="color: #0000ff;">car</span> (last (split-string parent <span style="color: #ff0000;">"/"</span> t)))))
(split-window-vertically (- height))
(other-window 1)
(eshell <span style="color: #ff0000;">"new"</span>)
(rename-buffer (concat <span style="color: #ff0000;">"*eshell: "</span> name <span style="color: #ff0000;">"*"</span>))
(insert (concat <span style="color: #ff0000;">"ls"</span>))
(eshell-send-input)))
</pre>
</div>
<p>
via howardism
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eshell-there</span> (host)
<span style="color: #cd6600;">"Opens a shell on a remote host using tramp."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"sHost: "</span>)
(<span style="color: #0000ff;">let</span> ((default-directory (format <span style="color: #ff0000;">"/%s:"</span> host)))
(eshell host)))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'es</span> <span style="color: #ff00ff;">'eshell-here</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'et</span> <span style="color: #ff00ff;">'eshell-there</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'eshell</span>/vi <span style="color: #ff00ff;">'eshell</span>/emacs)
</pre>
</div>
<p>
plan9 smart command, edit while exec if not silent or successful
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'em-smart</span>)
</pre>
</div>
<p>
eshell shell aliases. I set the global
defvar here so there's no need to transport
~/.emacs.d/eshell/aliases across networks
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> eshell-command-aliases-list ())
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">+alias</span> (al cmd)
<span style="color: #cd6600;">"handy wrapper function to convert alias symbols</span>
<span style="color: #cd6600;">to alias strings to avoid writing 4 quotes per alias.</span>
<span style="color: #cd6600;">AL is a single-word symbol naming the alias, CMD is</span>
<span style="color: #cd6600;">a list symbol describing the command."</span>
(add-to-list <span style="color: #ff00ff;">'eshell-command-aliases-list</span>
(list (symbol-name al)
(mapconcat <span style="color: #ff00ff;">'symbol-name</span> cmd <span style="color: #ff0000;">" "</span>))))
</pre>
</div>
<p>
actual aliases
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(+alias <span style="color: #ff00ff;">'l</span> '(ls -laF $*))
(+alias <span style="color: #ff00ff;">'ll</span> '(ls -l $*))
(+alias <span style="color: #ff00ff;">'la</span> '(ls -a $*))
(+alias <span style="color: #ff00ff;">'lt</span> '(ls -ltr $*))
(+alias '.. '(cd ..))
(+alias '... '(cd ../..))
(+alias '.... '(cd ../../..))
(+alias '..... '(cd ../../../..))
(+alias <span style="color: #ff00ff;">'md</span> '(mkdir -p $*))
(+alias <span style="color: #ff00ff;">'emacs</span> '(find-file $1))
(+alias <span style="color: #ff00ff;">'less</span> '(find-file-read-only $1))
(+alias <span style="color: #ff00ff;">'x</span> '(eshell/exit))
</pre>
</div>
<p>
no need for less or more, this is emacs, isn't it?
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(setenv <span style="color: #ff0000;">"PAGER"</span> <span style="color: #ff0000;">"cat"</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org595dd72" class="outline-4">
<h4 id="org595dd72"><span class="section-number-4">6.4.2</span> Emacs LISP interactive</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-2">
<p>
General configuration for all things elisp.
</p>
<p>
By using C-x-e I can push region or buffer
of lisp code (i.e. inside <b>scratch</b>) into
REPL where it will be evaluated
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-get-code</span>()
<span style="color: #cd6600;">"helper: returns marked region or the whole buffer contents"</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">/</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #006400;">/: mv to string helpers?</span>
(<span style="color: #0000ff;">if</span> mark-active
(<span style="color: #0000ff;">let</span> ( <span style="color: #006400;">;; </span><span style="color: #006400;">save region and buffer</span>
(partb (buffer-substring-no-properties (region-beginning) (region-end)))
(whole (buffer-substring-no-properties (point-min) (point-max)))
)
(<span style="color: #0000ff;">if</span> (&gt; (length partb) 0)
partb
whole
)
)
<span style="color: #006400;">;; </span><span style="color: #006400;">no mark, also return everything</span>
(buffer-substring-no-properties (point-min) (point-max))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-send-region-to-repl</span> ()
<span style="color: #cd6600;">"put region or buffer into elisp repl and eval"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ( <span style="color: #006400;">;; </span><span style="color: #006400;">fetch region or buffer contents</span>
(code (tvd-get-code)))
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (get-buffer <span style="color: #ff0000;">"*ielm*"</span>))
<span style="color: #006400;">;; </span><span style="color: #006400;">ielm not yet running, start it in split window but stay here</span>
(<span style="color: #0000ff;">progn</span>
(split-window-horizontally)
(other-window 1)
(ielm)
(other-window 1)))
<span style="color: #006400;">;; </span><span style="color: #006400;">finially, paste content into ielm and evaluate it</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">still we stay where we are</span>
(<span style="color: #0000ff;">with-current-buffer</span> <span style="color: #ff0000;">"*ielm*"</span>
(goto-char (point-max))
(insert code)
(ielm-return)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-elisp-eval</span>()
<span style="color: #cd6600;">"just eval region or buffer whatever feasible"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> mark-active
(eval-region)
(eval-buffer))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">ff</span> ()
<span style="color: #cd6600;">"Jump to function definition at point."</span>
(<span style="color: #0000ff;">interactive</span>)
(find-function-other-window (symbol-at-point)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-make-defun-links</span> ()
<span style="color: #cd6600;">"experimental: make function calls clickable, on click, jump to definition of it"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((beg 0)
(end 0)
(fun nil))
(goto-char (point-min))
(<span style="color: #0000ff;">while</span> (re-search-forward <span style="color: #ff0000;">"(tvd[-a-z0-9]*"</span> nil t)
(<span style="color: #0000ff;">setq</span> end (point))
(re-search-backward <span style="color: #ff0000;">"("</span> nil t)
(forward-char 1)
(<span style="color: #0000ff;">setq</span> beg (point))
(<span style="color: #0000ff;">setq</span> fun (buffer-substring-no-properties beg end))
(make-button beg end <span style="color: #ff00ff;">'action</span>
(<span style="color: #0000ff;">lambda</span> (x)
(find-function-other-window (symbol-at-point))))
(goto-char end))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">emacs-change-version</span> (v)
<span style="color: #cd6600;">"Change version of .emacs (must be the current buffer).</span>
<span style="color: #cd6600;">Returns t if version changed, nil otherwise."</span>
(<span style="color: #0000ff;">interactive</span>
(list
(completing-read <span style="color: #ff0000;">"New config version (press TAB for old): "</span>
(list tvd-emacs-version))))
(<span style="color: #0000ff;">if</span> (equal v tvd-emacs-version)
nil
(<span style="color: #0000ff;">save-excursion</span>
(show-all)
(beginning-of-buffer)
(tvd-replace-all (format <span style="color: #ff0000;">"\"%s\""</span> tvd-emacs-version)
(format <span style="color: #ff0000;">"\"%s\""</span> v))
(<span style="color: #0000ff;">setq</span> tvd-emacs-version v)
(message (format <span style="color: #ff0000;">"New config version set: %s"</span> v))
t)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">emacs-change-log</span> (entry)
<span style="color: #cd6600;">"Add a changelog entry to .emacs Changelog"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"Menter change log entry: "</span>)
(<span style="color: #0000ff;">let</span> ((newversion (call-interactively <span style="color: #ff00ff;">'emacs-change-version</span>)))
(<span style="color: #0000ff;">save-excursion</span>
(show-all)
(beginning-of-buffer)
(re-search-forward <span style="color: #ff0000;">";; .. Changelog"</span>)
(next-line)
(tvd-outshine-end-of-section)
(<span style="color: #0000ff;">when</span> newversion
(insert (format <span style="color: #ff0000;">"\n;; %s\n"</span> tvd-emacs-version)))
(insert (format <span style="color: #ff0000;">";; - %s\n"</span> entry)))))
</pre>
</div>
<p>
elisp config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'emacs-lisp-mode-hook</span>
(<span style="color: #0000ff;">lambda</span>()
<span style="color: #006400;">;; </span><span style="color: #006400;">non-separated x-e == eval hidden, aka current buffer</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-e"</span>) <span style="color: #ff00ff;">'tvd-elisp-eval</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">separate 'e' == separate buffer</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x e"</span>) <span style="color: #ff00ff;">'tvd-send-region-to-repl</span>)
(<span style="color: #0000ff;">setq</span> mode-name <span style="color: #ff0000;">"EL"</span>
show-trailing-whitespace t)
(eldoc-mode t)
<span style="color: #006400;">;; </span><span style="color: #006400;">enable outline (with outshine)</span>
(outline-minor-mode)
<span style="color: #006400;">;; </span><span style="color: #006400;">enable outshine mode</span>
(outshine-hook-function)
(electric-indent-mode t)))
</pre>
</div>
<p>
use UP arrow for history in <b>ielm</b> as well, just as C-up
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'comint-mode-hook</span>
(<span style="color: #0000ff;">lambda</span>()
(define-key comint-mode-map [up] <span style="color: #ff00ff;">'comint-previous-input</span>)))
</pre>
</div>
<p>
sometimes I use lisp in minibuffer
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">ee</span>()
(<span style="color: #0000ff;">interactive</span>)
(electric-pair-mode)
(call-interactively <span style="color: #ff00ff;">'eval-expression</span>)
(electric-pair-mode))
</pre>
</div>
<p>
sometimes I eval regions
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'er</span> <span style="color: #ff00ff;">'eval-region</span>)
</pre>
</div>
<p>
&#x2026; or defuns
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ef</span> <span style="color: #ff00ff;">'eval-defun</span>)
</pre>
</div>
<p>
I like to have some functions fontified differently
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(font-lock-add-keywords
<span style="color: #ff00ff;">'emacs-lisp-mode</span>
'((<span style="color: #ff0000;">"(\\s-*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">eq</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">if</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">cond</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">and</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">set</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">or</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">not</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">when</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">setq</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">let**</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">lambda</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">kbd</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">defun</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">car</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">cdr</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">\\s-+"</span>
1 <span style="color: #ff00ff;">'font-lock-keyword-face</span>)))
</pre>
</div>
<p>
same applies for quoted symbols
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(font-lock-add-keywords
<span style="color: #ff00ff;">'emacs-lisp-mode</span>
'((<span style="color: #ff0000;">"'[-a-zA-Z_][-a-zA-Z0-9_]*\\&gt;"</span> 0 <span style="color: #ff00ff;">'font-lock-constant-face</span>)))
</pre>
</div>
<p>
I hate it when help, debug, ielm and other peripheral buffers
litter my emacs window setup. So, this function fixes this: it
opens a new frame with all those buffers already opened and pinned.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">dev</span> ()
<span style="color: #cd6600;">"Open a new emacs frame with some development peripheral buffers."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((F (new-frame)))
(<span style="color: #0000ff;">with-selected-frame</span> F
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*Help*"</span>)
(help-mode))
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*ielm*"</span>)
(ielm))
(<span style="color: #0000ff;">with-current-buffer</span> (get-buffer-create <span style="color: #ff0000;">"*suggest*"</span>)
(suggest))
(switch-to-buffer <span style="color: #ff0000;">"*ielm*"</span>)
(split-window-horizontally)
(split-window-vertically)
(windmove-down)
(switch-to-buffer <span style="color: #ff0000;">"*suggest*"</span>)
(tvd-suggest-reload)
(tvd-suggest-reload)
(windmove-right)
(switch-to-buffer <span style="color: #ff0000;">"*Help*"</span>)
(split-window-vertically)
(windmove-down)
(switch-to-buffer <span style="color: #ff0000;">"*scratch*"</span>)
(set-window-dedicated-p (selected-window) t)
(set-background-color <span style="color: #ff0000;">"azure"</span>))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgdfa3a7c" class="outline-4">
<h4 id="orgdfa3a7c"><span class="section-number-4">6.4.3</span> el2markdown</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-3">
<p>
<a href="https://github.com/Lindydancer/el2markdown">el2markdown</a> is a module which
can be used to convert Commentary sections into markdown files. I use this to
avoid maintaining the README.md and the Commentary section in parallel.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'el2markdown</span>)
</pre>
</div>
<p>
To use, call el2markdown-view-buffer and put it into the
README.md. Take care though: it doesn't convert the META section.
</p>
<p>
<i>FIXME</i>: write a wrapper to circumvent these restrictions.
</p>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgcca9912" class="outline-4">
<h4 id="orgcca9912"><span class="section-number-4">6.4.4</span> tramp mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-4">
<p>
Edit remote files, one of the best things in emacs. I use it every day heavily.
</p>
<p>
Sample: C-x-f /$host:/$file ($host as of .ssh/config or direct, $file including completion)
</p>
<p>
doku: <a href="http://www.gnu.org/software/tramp/">gnu.org</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tramp-default-method <span style="color: #ff0000;">"ssh"</span>
tramp-default-user nil
tramp-verbose 1
ido-enable-tramp-completion t)
</pre>
</div>
<p>
see also backup section
</p>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org264e425" class="outline-4">
<h4 id="org264e425"><span class="section-number-4">6.4.5</span> org mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-5">
<p>
I use org mode to take notes mostly at work. I also track projects
and TODO lists etc. I do not, however, use agenda or any
scheduling whatsoever.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'org</span>)
</pre>
</div>
<p>
I like custom bullets
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'org-bullets</span>)
</pre>
</div>
<p>
enable syntax highlighting for embedded source blocks
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'ob-python</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'ob-perl</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'ob-shell</span>)
(<span style="color: #0000ff;">setq</span> org-bullets-bullet-list '(<span style="color: #ff0000;">"&#9658;"</span> <span style="color: #ff0000;">"&#10012;"</span> <span style="color: #ff0000;">"&#10040;"</span> <span style="color: #ff0000;">"&#10047;"</span> <span style="color: #ff0000;">"&#9830;"</span>))
</pre>
</div>
<p>
capture target, os-dependend
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (null tvd-win-home)
(<span style="color: #0000ff;">setq</span> tvd-org-file (concat tvd-lisp-dir <span style="color: #ff0000;">"/notizen.org"</span>)
org-attach-directory (concat tvd-lisp-dir <span style="color: #ff0000;">"/attachments"</span>))
(<span style="color: #0000ff;">setq</span> tvd-org-file (concat tvd-win-home <span style="color: #ff0000;">"/notizen.org"</span>)
org-attach-directory (concat tvd-win-home <span style="color: #ff0000;">"/attachments"</span>)))
</pre>
</div>
<p>
text formatting made easy, bound to C-c keys locally
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-emphasize</span>(CHAR)
<span style="color: #cd6600;">"expand once if no region and apply emphasize CHAR"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">unless</span> (region-active-p)
(er/expand-region 1))
(org-emphasize CHAR))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">bold</span>()
<span style="color: #cd6600;">"bold text in org mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-emphasize '42))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">italic</span>()
<span style="color: #cd6600;">"italic text in org mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-emphasize '47))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">code</span>()
<span style="color: #cd6600;">"verbatim text in org mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-emphasize '126))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">underline</span>()
<span style="color: #cd6600;">"underline text in org mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-emphasize '95))
</pre>
</div>
<p>
my org-mode specific &lt;C-left&gt; and &lt;C-right&gt;
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-left-or-level-up</span>()
<span style="color: #cd6600;">"jump one word to the left if not on a org heading,</span>
<span style="color: #cd6600;">otherwise fold current level and jump one level up."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">and</span> (org-at-heading-p) (looking-at <span style="color: #ff0000;">"*"</span>))
(<span style="color: #0000ff;">progn</span>
(hide-subtree)
(outline-up-heading 1))
(left-word)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-heading-up</span>()
<span style="color: #cd6600;">"If on a heading, fold current heading, jump one level</span>
<span style="color: #cd6600;">up and unfold it, otherwise jump paragraph as usual."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">and</span> (org-at-heading-p) (looking-at <span style="color: #ff0000;">"*"</span>))
(<span style="color: #0000ff;">progn</span>
(hide-subtree)
(org-backward-heading-same-level 1)
(org-cycle))
(backward-paragraph)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-heading-down</span>()
<span style="color: #cd6600;">"If on a heading, fold current heading, jump one level</span>
<span style="color: #cd6600;">down and unfold it, otherwise jump paragraph as usual."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">and</span> (org-at-heading-p) (looking-at <span style="color: #ff0000;">"*"</span>))
(<span style="color: #0000ff;">progn</span>
(hide-subtree)
(org-forward-heading-same-level 1)
(org-cycle))
(forward-paragraph)))
</pre>
</div>
<p>
org-mode specific config, after load
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"org"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'org-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">setq</span>
org-M-RET-may-split-line nil
org-agenda-files (list tvd-org-file)
org-agenda-restore-windows-after-quit t
org-blank-before-new-entry (<span style="color: #0000ff;">quote</span> ((heading . auto) (plain-list-item . auto)))
org-catch-invisible-edits (<span style="color: #0000ff;">quote</span> error)
org-columns-default-format <span style="color: #ff0000;">"%80ITEM %22Timestamp %</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> %TAGS %0PRIORITY"</span>
org-insert-heading-always-after-current (<span style="color: #0000ff;">quote</span> t)
org-mouse-1-follows-link nil
org-remember-store-without-prompt t
org-reverse-note-order t
org-startup-indented t
org-startup-truncated nil
org-return-follows-link t
org-use-speed-commands t
org-yank-adjusted-subtrees t
org-refile-targets '((nil . (<span style="color: #8a2be2;">:maxlevel</span> . 5)))
org-refile-use-outline-path t
org-outline-path-complete-in-steps nil
org-completion-use-ido t
org-support-shift-select t
org-hide-emphasis-markers t
org-fontify-done-headline t
org-pretty-entities t
org-use-sub-superscripts nil
org-confirm-babel-evaluate nil)
<span style="color: #006400;">; </span><span style="color: #006400;">shortcuts</span>
(<span style="color: #0000ff;">setq</span> org-speed-commands-user
(<span style="color: #0000ff;">quote</span> (
(<span style="color: #ff0000;">"0"</span> . ignore)
(<span style="color: #ff0000;">"1"</span> . delete-other-windows)
(<span style="color: #ff0000;">"2"</span> . ignore)
(<span style="color: #ff0000;">"3"</span> . ignore)
(<span style="color: #ff0000;">"d"</span> . org-archive-subtree-default-with-confirmation) <span style="color: #006400;">; </span><span style="color: #006400;">delete, keep track</span>
(<span style="color: #ff0000;">"v"</span> . org-narrow-to-subtree) <span style="color: #006400;">; </span><span style="color: #006400;">only show current heading ("view")</span>
(<span style="color: #ff0000;">"q"</span> . widen) <span style="color: #006400;">; </span><span style="color: #006400;">close current heading and show all ("quit")</span>
(<span style="color: #ff0000;">":"</span> . org-set-tags-command) <span style="color: #006400;">; </span><span style="color: #006400;">add/edit tags</span>
(<span style="color: #ff0000;">"t"</span> . org-todo) <span style="color: #006400;">; </span><span style="color: #006400;">toggle todo type, same as C-t</span>
(<span style="color: #ff0000;">"z"</span> . org-refile) <span style="color: #006400;">; </span><span style="color: #006400;">archive the (sub-)tree</span>
(<span style="color: #ff0000;">"a"</span> . org-attach) <span style="color: #006400;">; </span><span style="color: #006400;">manage attachments</span>
)))
<span style="color: #006400;">; </span><span style="color: #006400;">same as toggle</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-t"</span>) <span style="color: #ff00ff;">'org-todo</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">alt-enter = insert new subheading below current</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;M-return&gt;"</span>) <span style="color: #ff00ff;">'org-insert-subheading</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">search for tags (ends up in agenda view)</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-f"</span>) <span style="color: #ff00ff;">'org-tags-view</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">run presenter, org-present must be installed and loadedwhite</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-p"</span>) <span style="color: #ff00ff;">'org-present</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">todo colors</span>
(<span style="color: #0000ff;">setq</span> org-todo-keyword-faces '(
(<span style="color: #ff0000;">"</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;">"</span> . (<span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"#b70101"</span> <span style="color: #8a2be2;">:weight</span> bold))
(<span style="color: #ff0000;">"START"</span> . (<span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"blue"</span> <span style="color: #8a2be2;">:weight</span> bold))
(<span style="color: #ff0000;">"WAIT"</span> . (<span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"darkorange"</span> <span style="color: #8a2be2;">:weight</span> bold))
(<span style="color: #ff0000;">"DONE"</span> . (<span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"forestgreen"</span> <span style="color: #8a2be2;">:weight</span> bold))
(<span style="color: #ff0000;">"CANCEL"</span> . (<span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"red"</span> <span style="color: #8a2be2;">:weight</span> bold))
))
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c b"</span>) <span style="color: #ff00ff;">'bold</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c /"</span>) <span style="color: #ff00ff;">'italic</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c 0"</span>) <span style="color: #ff00ff;">'code</span>) <span style="color: #006400;">; </span><span style="color: #006400;">aka = without shift</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c _"</span>) <span style="color: #ff00ff;">'underline</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">edit babel src block in extra buffer:</span>
<span style="color: #006400;">; </span><span style="color: #006400;">default is C-c ' which is hard to type</span>
<span style="color: #006400;">; </span><span style="color: #006400;">brings me to src code editor buffer</span>
<span style="color: #006400;">; </span><span style="color: #006400;">Also note: enter &lt;s then TAB inserts a code block</span>
<span style="color: #006400;">; </span><span style="color: #006400;">Next, C-c C-c executes the code, adding :results table at the</span>
<span style="color: #006400;">; </span><span style="color: #006400;">end of the begin line, creates a table of the output</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-#"</span>) <span style="color: #ff00ff;">'org-edit-special</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">faster jumping</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-up&gt;"</span>) <span style="color: #ff00ff;">'tvd-org-heading-up</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-down&gt;"</span>) <span style="color: #ff00ff;">'tvd-org-heading-down</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">move word left or heading up, depending where point is</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-left&gt;"</span>) <span style="color: #ff00ff;">'tvd-org-left-or-level-up</span>)
<span style="color: #006400;">; </span><span style="color: #006400;">use nicer bullets</span>
(org-bullets-mode 1)
(org-babel-do-load-languages <span style="color: #ff00ff;">'org-babel-load-languages</span>
'((python . t)
(emacs-lisp . t)
(shell . t)
(perl . t)))))))
</pre>
</div>
<p>
no more &#x2026; at the end of a heading
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> org-ellipsis <span style="color: #ff0000;">" &#10549;"</span>)
</pre>
</div>
<p>
my own keywords, must be set globally, not catched correctly inside hook
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> org-todo-keywords
'((sequence <span style="color: #ff0000;">"</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;">"</span> <span style="color: #ff0000;">"START"</span> <span style="color: #ff0000;">"WAIT"</span> <span style="color: #ff0000;">"|"</span> <span style="color: #ff0000;">"DONE"</span> <span style="color: #ff0000;">"CANCEL"</span>)))
</pre>
</div>
<p>
I always want to be able to capture, even if no ORG is running
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-n"</span>) (<span style="color: #0000ff;">lambda</span> () (<span style="color: #0000ff;">interactive</span>) (org-capture)))
</pre>
</div>
<p>
must be global since code edit sub buffers run their own major mode, not org
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-#"</span>) <span style="color: #ff00ff;">'org-edit-src-exit</span>)
</pre>
</div>
<p>
some org mode vars must be set globally
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> org-default-notes-file tvd-org-file
org-startup-indented t
org-indent-indentation-per-level 4)
</pre>
</div>
<p>
my own capture templates
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> org-capture-templates
'((<span style="color: #ff0000;">"n"</span> <span style="color: #ff0000;">"Project"</span> entry (file+headline tvd-org-file <span style="color: #ff0000;">"Unsorted Tasks"</span>)
<span style="color: #ff0000;">"* </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> %^{title}\n%u\n** Kostenstelle\n** Contact Peer\n** Contact Customer\n** Auftr&#228;ge\n** Daten\n** Notizen\n %i%?\n"</span>
<span style="color: #8a2be2;">:prepend</span> t <span style="color: #8a2be2;">:jump-to-captured</span> t)
(<span style="color: #ff0000;">"t"</span> <span style="color: #ff0000;">"Todo Item"</span> entry (file+headline tvd-org-file <span style="color: #ff0000;">"Manual-Agenda-Tasks"</span>)
<span style="color: #ff0000;">"* </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> %^{title}\n:LOGBOOK:\n%u:END:\n"</span> <span style="color: #8a2be2;">:prepend</span> t <span style="color: #8a2be2;">:immediate-finish</span> t)
(<span style="color: #ff0000;">"s"</span> <span style="color: #ff0000;">"Scheduled Item"</span> entry (file+headline tvd-org-file <span style="color: #ff0000;">"Scheduled-Agenda-Tasks"</span>)
<span style="color: #ff0000;">"* </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> %^t %^{title}\n:LOGBOOK:\n%u:END:\n"</span> <span style="color: #8a2be2;">:prepend</span> t <span style="color: #8a2be2;">:immediate-finish</span> t)
(<span style="color: #ff0000;">"j"</span> <span style="color: #ff0000;">"Journal"</span> entry (file+headline tvd-org-file <span style="color: #ff0000;">"Kurznotizen"</span>)
<span style="color: #ff0000;">"* </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> %^{title}\n%u\n %i%?\n"</span> <span style="color: #8a2be2;">:prepend</span> t <span style="color: #8a2be2;">:jump-to-captured</span> t)
(<span style="color: #ff0000;">"c"</span> <span style="color: #ff0000;">"Copy/Paste"</span> entry (file+headline tvd-org-file <span style="color: #ff0000;">"Kurznotizen"</span>)
<span style="color: #ff0000;">"* </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> %^{title}\n%u\n %x\n"</span> <span style="color: #8a2be2;">:immediate-finish</span> t <span style="color: #8a2be2;">:prepend</span> t <span style="color: #8a2be2;">:jump-to-captured</span> t)))
</pre>
</div>
<p>
follow links using eww, if present
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (fboundp <span style="color: #ff00ff;">'eww-browse-url</span>)
(<span style="color: #0000ff;">setq</span> browse-url-browser-function <span style="color: #ff00ff;">'eww-browse-url</span>))
</pre>
</div>
<p>
mark narrowing with an orange fringe, the advice for 'widen
is in the outline section.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(advice-add <span style="color: #ff00ff;">'org-narrow-to-subtree</span> <span style="color: #8a2be2;">:after</span>
'(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args)
(set-face-attribute <span style="color: #ff00ff;">'fringe</span> nil <span style="color: #8a2be2;">:background</span> tvd-fringe-narrow-bg)))
</pre>
</div>
<p>
always use the latest docs
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">with-eval-after-load</span> <span style="color: #ff00ff;">'info</span>
(info-initialize)
(add-to-list <span style="color: #ff00ff;">'Info-directory-list</span>
(expand-file-name <span style="color: #ff0000;">"~/.emacs.d/lisp/org/doc"</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org3308fc0" class="outline-4">
<h4 id="org3308fc0"><span class="section-number-4">6.4.6</span> org agenda mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-6">
<p>
I use org mode for along time now, primarily at work, but did not
use agenda. Instead I developed the habit of maintaining one org
entry which contains just a list with all things to do today. I
just edited this list manually and it worked. However, recently I
found out that agenda provides lots of features and commands
precisely for what I already did manually. So, now, finally (as of
november 2018) I switch to using the agenda.
</p>
<p>
My agenda use is very simple though: I don't use any scheduling, no
priorities, no recurring events, no daily or other time based
views. I just keep a list of TODO entries and another of entries in
WAIT state, that's it. All those entries are located under a
special org entry with the title "Heute" and the category (as
property) WORK, which I use for filtering out agenda items.
</p>
<p>
The general workflow is as follows: I execute (agenda) which starts
directly my custom agenda view. It lists open TODO items and
waiting WAIT items below. If I press `n', I will be asked for a
title and a new TODO item appears in my agenda. I can press `d' to
mark it as DONE, it will also be archived into a subsibling below
"HEUTE". I can press `w' to move an item into WAIT state and I can
press `a' to add text to the org entry under point (like "waiting
for customer email").
</p>
<p>
So, I don't use my regular org entries, which are in most cases
very large containing lots of information, as agenda items, but
only very short ones which act as reminders about what work I have
to do. However, since I have the org buffer always opened and
visible in a split buffer next to the agenda, it is no problem to
go to such a deep entry for editing or viewing.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'org-agenda</span>)
</pre>
</div>
<p>
This is my one and only agenda custom view, it displays TODO items
below entries categorized as WORK and WAIT items under the same
category. The cool thing here is, that the `tags' agenda view can
be used to filter for properties as well. In order to have this
working the following property drawer must exist in an entry with
TODO siblings:
</p>
<ul class="org-ul">
<li><p>
START Arbeit
</p>
<p>
:CATEGORY: WORK
</p></li>
</ul>
<p>
<b>* TODO a thing to do
*</b> WAIT a thing waiting for something
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> org-agenda-custom-commands
'((<span style="color: #ff0000;">"o"</span> <span style="color: #ff0000;">"Daily </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;"> Tasks"</span>
(
<span style="color: #006400;">;; </span><span style="color: #006400;">a block containing only items scheduled for today, if any</span>
(agenda <span style="color: #ff0000;">""</span>
((org-agenda-span 1)
(org-agenda-overriding-header <span style="color: #ff0000;">"Tasks scheduled:"</span>)))
<span style="color: #006400;">;; </span><span style="color: #006400;">manually created todo items due (state </span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #006400;">)</span>
(tags <span style="color: #ff0000;">"CATEGORY=\"WORK\""</span>
((org-agenda-skip-function '(org-agenda-skip-entry-if <span style="color: #ff00ff;">'todo</span> '(<span style="color: #ff0000;">"CANCEL"</span> <span style="color: #ff0000;">"START"</span> <span style="color: #ff0000;">"DONE"</span> <span style="color: #ff0000;">"WAIT"</span>)))
(org-agenda-overriding-header <span style="color: #ff0000;">"\nTasks to do today:"</span>)
(org-agenda-follow-mode t)
(org-agenda-entry-text-mode t)))
<span style="color: #006400;">;; </span><span style="color: #006400;">manually created todo items in wait state</span>
(tags <span style="color: #ff0000;">"CATEGORY=\"WORK\""</span>
((org-agenda-skip-function '(org-agenda-skip-entry-if <span style="color: #ff00ff;">'todo</span> '(<span style="color: #ff0000;">"CANCEL"</span> <span style="color: #ff0000;">"START"</span> <span style="color: #ff0000;">"DONE"</span> <span style="color: #ff0000;">"</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">TODO</span><span style="color: #ff0000;">"</span>)))
(org-agenda-overriding-header <span style="color: #ff0000;">"\nTasks Waiting:"</span>))))
((org-agenda-compact-blocks t)))))
</pre>
</div>
<p>
A shortcut to reach my custom view directly
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">agenda</span> ()
<span style="color: #cd6600;">"Visit my org agenda directly, splits left"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-agenda nil <span style="color: #ff0000;">"o"</span>)
(tvd-flip-windows)
(other-window-or-switch-buffer))
</pre>
</div>
<p>
Add a line of text to the top of an existing TODO entry and refresh
the agenda
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-edit-entry</span> (note)
<span style="color: #cd6600;">"Insert a note as plain text into an entry"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"sEnter note: "</span>)
(<span style="color: #0000ff;">save-excursion</span>
(org-agenda-switch-to)
(end-of-line)
(newline)
(insert note))
(switch-to-buffer <span style="color: #ff0000;">"*Org Agenda*"</span>)
(org-agenda-redo t))
</pre>
</div>
<p>
Mark an entry as DONE, archive it to an archive sibling and refresh
the agenda
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-done</span>()
(<span style="color: #0000ff;">interactive</span>)
(org-agenda-todo <span style="color: #ff00ff;">'done</span>)
(org-agenda-archive-to-archive-sibling)
(org-agenda-redo t))
</pre>
</div>
<p>
Mark an entry as WAIT, archive it to an archive sibling and refresh
the agenda
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-wait</span>()
(<span style="color: #0000ff;">interactive</span>)
(org-agenda-todo <span style="color: #ff0000;">"WAIT"</span>)
(org-agenda-redo t))
</pre>
</div>
<p>
A wrapper which executes an org capture directly. `t' is the
shortcut for the capture, defined above in org mode.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-capture</span> (task)
<span style="color: #cd6600;">"Capture a task in agenda mode, using the date at point"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((org-overriding-default-time (org-get-cursor-date)))
(org-capture nil task)
(org-agenda-redo t)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-capture-todo</span> ()
<span style="color: #cd6600;">"Capture a todo task in agenda mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-agenda-capture <span style="color: #ff0000;">"t"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-capture-scheduled</span> ()
<span style="color: #cd6600;">"Capture a scheduled task in agenda mode"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-agenda-capture <span style="color: #ff0000;">"s"</span>))
</pre>
</div>
<p>
Sometimes it is nice to see the agenda alone, so I press
`o'. However, since follow mode is enabled, once I move point, the
org buffer re-appears.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-solitair</span> ()
(<span style="color: #0000ff;">interactive</span>)
(delete-other-windows)
(<span style="color: #0000ff;">setq</span> org-agenda-follow-mode nil)
(message <span style="color: #ff0000;">"Org Agenda Follow Mode Disabled"</span>))
</pre>
</div>
<p>
The original function scrolls the buffer every time when it runs a
little bit up, which is annoying, to say the least
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-agenda-redo</span>()
(<span style="color: #0000ff;">interactive</span>)
(org-agenda-redo t)
(beginning-of-buffer))
</pre>
</div>
<p>
Since I learned to love hydra, I have one for my agenda as well, of course:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defhydra</span> hydra-org-agenda (<span style="color: #8a2be2;">:color</span> blue
<span style="color: #8a2be2;">:pre</span> (<span style="color: #0000ff;">setq</span> which-key-inhibit t)
<span style="color: #8a2be2;">:post</span> (<span style="color: #0000ff;">setq</span> which-key-inhibit nil)
<span style="color: #8a2be2;">:hint</span> none)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">Org Agenda (_q_uit)</span>
<span style="color: #cd6600;">^Tasks^ ^Options^ ^Movement^</span>
<span style="color: #cd6600;">-^^^^^^-------------------------------------------------------------------------------------</span>
<span style="color: #cd6600;">_n_: create new todo task _f_: follow =?f? ENTER: switch to entry</span>
<span style="color: #cd6600;">_N_: create new scheduled task _e_: entry =?e? C-&lt;up&gt;: go one entry up</span>
<span style="color: #cd6600;">_d_: mark task done and archive _o_: one window C-&lt;down&gt;: go one entry down</span>
<span style="color: #cd6600;">_w_: mark task waiting ^^ M-&lt;up&gt;: move entry up</span>
<span style="color: #cd6600;">_t_: toggle todo state ^^ M-&lt;down&gt;: move entry down</span>
<span style="color: #cd6600;">_z_: archive task ^ ^</span>
<span style="color: #cd6600;">_+_: increase prio</span>
<span style="color: #cd6600;">_-_: decrease prio ^Marking^</span>
<span style="color: #cd6600;">_g_: refresh _m_: mark entry</span>
<span style="color: #cd6600;">_s_: save org buffer(s) _u_: un-mark entry</span>
<span style="color: #cd6600;">_a_: add a note to the entry _U_: un-mark all</span>
<span style="color: #cd6600;">_k_: delete a task w/o archiving _B_: bulk action</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"a"</span> tvd-org-agenda-edit-entry nil)
(<span style="color: #ff0000;">"n"</span> tvd-org-agenda-capture-todo nil)
(<span style="color: #ff0000;">"N"</span> tvd-org-agenda-capture-scheduled nil)
(<span style="color: #ff0000;">"o"</span> tvd-org-agenda-solitair nil)
(<span style="color: #ff0000;">"g"</span> tvd-org-agenda-redo)
(<span style="color: #ff0000;">"t"</span> org-agenda-todo)
(<span style="color: #ff0000;">"d"</span> tvd-org-agenda-done nil)
(<span style="color: #ff0000;">"w"</span> tvd-org-agenda-wait nil)
(<span style="color: #ff0000;">"z"</span> org-agenda-archive-to-archive-sibling nil)
(<span style="color: #ff0000;">"+"</span> org-agenda-priority-up nil)
(<span style="color: #ff0000;">"-"</span> org-agenda-priority-down nil)
(<span style="color: #ff0000;">"s"</span> org-save-all-org-buffers nil)
(<span style="color: #ff0000;">"f"</span> org-agenda-follow-mode
(format <span style="color: #ff0000;">"% -3S"</span> org-agenda-follow-mode))
(<span style="color: #ff0000;">"e"</span> org-agenda-entry-text-mode
(format <span style="color: #ff0000;">"% -3S"</span> org-agenda-entry-text-mode))
(<span style="color: #ff0000;">"m"</span> org-agenda-bulk-mark nil)
(<span style="color: #ff0000;">"u"</span> org-agenda-bulk-unmark nil)
(<span style="color: #ff0000;">"U"</span> org-agenda-bulk-remove-all-marks nil)
(<span style="color: #ff0000;">"B"</span> org-agenda-bulk-action nil)
(<span style="color: #ff0000;">"k"</span> org-agenda-kill nil)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
</pre>
</div>
<p>
Configuration and key bindings for org agenda (same as in the hydra)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'org-agenda-mode-hook</span> '(<span style="color: #0000ff;">lambda</span> () (<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">setq</span> org-agenda-follow-mode t
org-log-into-drawer t
org-agenda-entry-text-mode t
org-agenda-sorting-strategy '(priority-down timestamp-down))
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"n"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-capture-todo</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"N"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-capture-scheduled</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"o"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-solitair</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"a"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-edit-entry</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"d"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-done</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"w"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-wait</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"g"</span>) <span style="color: #ff00ff;">'tvd-org-agenda-redo</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"f"</span>) <span style="color: #ff00ff;">'org-agenda-follow-mode</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"e"</span>) <span style="color: #ff00ff;">'org-agenda-entry-text-mode</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"k"</span>) <span style="color: #ff00ff;">'org-agenda-kill</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"z"</span>) <span style="color: #ff00ff;">'org-agenda-archive-to-archive-sibling</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-&lt;up&gt;"</span>) <span style="color: #ff00ff;">'org-agenda-previous-item</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-&lt;down&gt;"</span>) <span style="color: #ff00ff;">'org-agenda-next-item</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"?"</span>) <span style="color: #ff00ff;">'hydra-org-agenda</span>/body))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org182c38f" class="outline-4">
<h4 id="org182c38f"><span class="section-number-4">6.4.7</span> org table mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-7">
<p>
I'm so used to lovely org mode tables, I need them everywhere!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'org-table</span>)
</pre>
</div>
<p>
convert CSV region to table
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tablify</span> (regex)
<span style="color: #cd6600;">"Convert a whitespace separated column list into</span>
<span style="color: #cd6600;">an org mode table and enable orgtbl-mode. You can</span>
<span style="color: #cd6600;">specify another regex for cell splitting."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"MConvert [region] to table with regex ([\t\s]+): "</span>)
(<span style="color: #0000ff;">let</span> ((spc <span style="color: #ff0000;">"[\t\s]+"</span>))
(<span style="color: #0000ff;">when</span> (string= regex <span style="color: #ff0000;">""</span>)
(<span style="color: #0000ff;">setq</span> regex spc))
(delete-trailing-whitespace)
(<span style="color: #0000ff;">if</span> (org-region-active-p)
(org-table-convert-region (region-beginning) (region-end) regex)
(org-table-convert-region (point-min) (point-max) regex))
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">not</span> (<span style="color: #0000ff;">eq</span> major-mode <span style="color: #ff00ff;">'org-mode</span>))
(orgtbl-mode))))
</pre>
</div>
<p>
table sorting shortcuts
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-numeric</span> ()
<span style="color: #cd6600;">"sort org table numerically by current column"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?n))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-numeric-desc</span> ()
<span style="color: #cd6600;">"reverse sort org table numerically by current column"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?N))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-alphanumeric</span> ()
<span style="color: #cd6600;">"sort org table charwise by current column"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?a))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-alphanumeric-desc</span> ()
<span style="color: #cd6600;">"reverse sort org table charwise by current column"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?A))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-time</span> ()
<span style="color: #cd6600;">"sort org table by times by current column"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?t))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-time-desc</span> ()
<span style="color: #cd6600;">"reverse sort org table by times by current column"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?T))
</pre>
</div>
<p>
<a href="http://irreal.org/blog/?p=3542">via jcs/irreal.org</a>
however, I renamed the actual sort wrappers to match my
naming scheme
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">jcs-ip-lessp</span> (ip1 ip2 <span style="color: #483d8b;">&amp;optional</span> op)
<span style="color: #cd6600;">"Compare two IP addresses.</span>
<span style="color: #cd6600;">Unless the optional argument OP is provided, this function will return T</span>
<span style="color: #cd6600;">if IP1 is less than IP2 or NIL otherwise. The optional argument OP is</span>
<span style="color: #cd6600;">intended to be #'&gt; to support reverse sorting."</span>
(<span style="color: #0000ff;">setq</span> cmp (<span style="color: #0000ff;">or</span> op #'&lt;))
(<span style="color: #0000ff;">cl-labels</span> ((compare (l1 l2)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">or</span> (null l1) (null l2))
nil
(<span style="color: #0000ff;">let</span> ((n1 (string-to-number (<span style="color: #0000ff;">car</span> l1)))
(n2 (string-to-number (<span style="color: #0000ff;">car</span> l2))))
(<span style="color: #0000ff;">cond</span>
((funcall cmp n1 n2) t)
((= n1 n2) (compare (<span style="color: #0000ff;">cdr</span> l1) (<span style="color: #0000ff;">cdr</span> l2)))
(t nil))))))
(compare (split-string ip1 <span style="color: #ff0000;">"\\."</span>) (split-string ip2 <span style="color: #ff0000;">"\\."</span>))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-ip</span> ()
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?f #<span style="color: #ff00ff;">'org-sort-remove-invisible</span> #<span style="color: #ff00ff;">'jcs-ip-lessp</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">sort-table-ip-desc</span> ()
(<span style="color: #0000ff;">interactive</span>)
(org-table-sort-lines nil ?F #<span style="color: #ff00ff;">'org-sort-remove-invisible</span>
(<span style="color: #0000ff;">lambda</span> (ip1 ip2) (jcs-ip-lessp ip1 ip2 #'&gt;))))
</pre>
</div>
<p>
easy access for the shortcuts
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'stn</span> <span style="color: #ff00ff;">'sort-table-numeric</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'stnd</span> <span style="color: #ff00ff;">'sort-table-numeric-desc</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'sta</span> <span style="color: #ff00ff;">'sort-table-alphanumeric</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'stad</span> <span style="color: #ff00ff;">'sort-table-alphanumeric-desc</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'stt</span> <span style="color: #ff00ff;">'sort-table-time</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'sttd</span> <span style="color: #ff00ff;">'sort-table-time-desc</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'sti</span> <span style="color: #ff00ff;">'sort-table-ip</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'stid</span> <span style="color: #ff00ff;">'sort-table-ip-desc</span>)
</pre>
</div>
<p>
generic table exporter
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-export-org-table</span> (fmt)
<span style="color: #cd6600;">"export an org table using format FMT"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((efile <span style="color: #ff0000;">"/tmp/org-table-export.tmp"</span>)
(ebuf (format <span style="color: #ff0000;">"*table-%s*"</span> fmt)))
(<span style="color: #0000ff;">when</span> (file-exists-p efile)
(delete-file efile))
(org-table-export efile (format <span style="color: #ff0000;">"orgtbl-to-%s"</span> fmt))
(other-window 1)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (<span style="color: #0000ff;">eq</span> (get-buffer ebuf) nil))
(kill-buffer (get-buffer ebuf)))
(set-buffer (get-buffer-create ebuf))
(insert-file-contents efile)
(switch-to-buffer ebuf)
(delete-file efile)))
</pre>
</div>
<p>
<i>FIXME</i>: once there's an org solution to this, remove this code
format specific exporters
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-quote-csv-field</span> (s)
<span style="color: #cd6600;">"Quote every field."</span>
(<span style="color: #0000ff;">if</span> (string-match <span style="color: #ff0000;">"."</span> s)
(concat <span style="color: #ff0000;">"=\""</span> (mapconcat <span style="color: #ff00ff;">'identity</span>
(split-string s <span style="color: #ff0000;">"\""</span>) <span style="color: #ff0000;">"\"\""</span>) <span style="color: #ff0000;">"\""</span>)
s))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">table-to-excel</span> ()
<span style="color: #cd6600;">"export current org table to CSV format suitable for MS Excel."</span>
(<span style="color: #0000ff;">interactive</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">quote everything, map temporarily 'org-quote-csv-field</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">to my version</span>
(<span style="color: #0000ff;">cl-letf</span> (((symbol-function <span style="color: #ff00ff;">'org-quote-csv-field</span>)
#<span style="color: #ff00ff;">'tvd-org-quote-csv-field</span>))
(tvd-export-org-table <span style="color: #ff0000;">"csv"</span>)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">table-to-csv</span> ()
<span style="color: #cd6600;">"export current org table to CSV format"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-export-org-table <span style="color: #ff0000;">"csv"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">table-to-latex</span> ()
<span style="color: #cd6600;">"export current org table to LaTeX format"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-export-org-table <span style="color: #ff0000;">"latex"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">table-to-html</span> ()
<span style="color: #cd6600;">"export current org table to HTML format"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-export-org-table <span style="color: #ff0000;">"html"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">table-to-csv-tab</span> ()
<span style="color: #cd6600;">"export current org table to CSV format, separated by &lt;tab&gt;"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-export-org-table <span style="color: #ff0000;">"tsv"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">table-to-aligned</span> ()
<span style="color: #cd6600;">"export current org table to space-aligned columns format"</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-export-org-table <span style="color: #ff0000;">"csv"</span>)
(<span style="color: #0000ff;">with-current-buffer</span> <span style="color: #ff0000;">"*table-csv*"</span>
(align-regexp (point-min) (point-max) <span style="color: #ff0000;">"</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">\\s-*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">,"</span> 1 1 t)
(<span style="color: #0000ff;">while</span> (re-search-forward <span style="color: #ff0000;">" ,"</span> nil t)
(replace-match <span style="color: #ff0000;">" "</span>))))
</pre>
</div>
<p>
exporter shortcuts
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ttc</span> <span style="color: #ff00ff;">'table-to-csv</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'tte</span> <span style="color: #ff00ff;">'table-to-excel</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ttl</span> <span style="color: #ff00ff;">'table-to-latex</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'tth</span> <span style="color: #ff00ff;">'table-to-html</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ttt</span> <span style="color: #ff00ff;">'table-to-csv-tab</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'tta</span> <span style="color: #ff00ff;">'table-to-aligned</span>)
</pre>
</div>
<p>
In org mode I sometimes want to copy the content of a table cell
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-beginning-of-cell</span> (<span style="color: #483d8b;">&amp;optional</span> arg)
<span style="color: #cd6600;">"move (point) to the beginning of a org mode table cell"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (re-search-backward <span style="color: #ff0000;">"|"</span> (line-beginning-position) 3 1)
(forward-char)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-end-of-cell</span> (<span style="color: #483d8b;">&amp;optional</span> arg)
<span style="color: #cd6600;">"move (point) to the end of a org mode table cell"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (re-search-forward <span style="color: #ff0000;">"|"</span> (line-end-position) 3 1)
(backward-char)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-copy-org-table-cell</span>(<span style="color: #483d8b;">&amp;optional</span> arg)
<span style="color: #cd6600;">"Copy an org mode table cell to the kill ring using MCYT"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>)
(mcyt--blink-and-copy-thing <span style="color: #ff00ff;">'tvd-beginning-of-cell</span> <span style="color: #ff00ff;">'tvd-end-of-cell</span> arg))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-del-org-table-cell</span> (<span style="color: #483d8b;">&amp;optional</span> arg)
<span style="color: #cd6600;">"Delete a cell"</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>)
(<span style="color: #0000ff;">let</span>
((beg (<span style="color: #0000ff;">progn</span> (tvd-beginning-of-cell) (point)))
(end (<span style="color: #0000ff;">progn</span> (tvd-end-of-cell) (point))))
(delete-region beg end)
(org-table-align)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-del-org-table-row</span> ()
<span style="color: #cd6600;">"Delete a table row's contents"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-beginning-of-line 1)
(kill-line)
(org-table-insert-row nil))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-del-org-table-col</span> ()
<span style="color: #cd6600;">"Delete a table column's contents, keep heading as is"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((head (org-table-get 1 nil)))
(org-table-delete-column)
(re-search-forward <span style="color: #ff0000;">"|"</span>)
(org-table-insert-column)
(tvd-org-table-goto-col-beginning)
(insert head)
(org-table-align))
)
</pre>
</div>
<p>
Sometimes I need to copy whole columns too:
via <a href="https://emacs.stackexchange.com/questions/28270/how-to-select-and-copy-a-column-of-an-org-table-without-rectangle-selection">stackoverflow</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-table-goto-col-beginning</span> ()
<span style="color: #cd6600;">"Go to beginning of current column and return `</span><span style="color: #cd6600;">point</span><span style="color: #cd6600;">'."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">assert</span> (org-table-p) <span style="color: #ff0000;">"Not in org-table."</span>)
(org-table-align)
(<span style="color: #0000ff;">let</span> ((col (org-table-current-column)))
(goto-char (org-table-begin))
(org-table-goto-column col))
(point))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-table-col-beginning</span> ()
<span style="color: #cd6600;">"Return beginning position of current column."</span>
(<span style="color: #0000ff;">save-excursion</span>
(tvd-org-table-goto-col-beginning)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-table-goto-col-end</span> ()
<span style="color: #cd6600;">"Goto end of current column and return `</span><span style="color: #cd6600;">point</span><span style="color: #cd6600;">'."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">assert</span> (org-table-p) <span style="color: #ff0000;">"Not in org-table."</span>)
(org-table-align)
(<span style="color: #0000ff;">let</span> ((col (org-table-current-column)))
(goto-char (1- (org-table-end)))
(org-table-goto-column col)
(skip-chars-forward <span style="color: #ff0000;">"^|"</span>))
(point))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-table-col-end</span> ()
<span style="color: #cd6600;">"Return end position of current column."</span>
(<span style="color: #0000ff;">save-excursion</span>
(tvd-org-table-goto-col-end)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-org-table-select-col</span> ()
<span style="color: #cd6600;">"Select current column."</span>
(<span style="color: #0000ff;">interactive</span>)
(set-mark (tvd-org-table-col-beginning))
(tvd-org-table-goto-col-end)
(rectangle-mark-mode))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-copy-org-table-col</span> ()
<span style="color: #cd6600;">"Copy current column."</span>
(<span style="color: #0000ff;">interactive</span>)
(tvd-org-table-select-col)
(sit-for 0.2 t)
(copy-region-as-kill nil nil t)
(<span style="color: #0000ff;">with-temp-buffer</span>
(yank)
(delete-trailing-whitespace)
(delete-whitespace-rectangle (point-min) (point-max))
(font-lock-unfontify-buffer)
(copy-region-as-kill (point-min) (point-max))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-copy-org-table-row</span> ()
<span style="color: #cd6600;">"Copy current row, space aligned"</span>
(<span style="color: #0000ff;">interactive</span>)
(mcyt-copy-line)
(<span style="color: #0000ff;">with-temp-buffer</span>
(yank)
(goto-char (point-min))
(<span style="color: #0000ff;">let</span> ((spc <span style="color: #ff0000;">""</span>))
(<span style="color: #0000ff;">while</span> (re-search-forward <span style="color: #ff0000;">"|[ ]*"</span> nil t)
(replace-match spc)
(<span style="color: #0000ff;">setq</span> spc <span style="color: #ff0000;">" "</span>)))
(delete-trailing-whitespace)
(copy-region-as-kill (point-min) (point-max))))
</pre>
</div>
<p>
Move single cells using C-M-up C-M-down C-M-left C-M-right
<a href="https://cs.gmu.edu/~kauffman/software/org-table-move-single-cell.el">via Kauffmann</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">org-table-swap-cells</span> (i1 j1 i2 j2)
<span style="color: #cd6600;">"Swap two cells"</span>
(<span style="color: #0000ff;">let</span> ((c1 (org-table-get i1 j1))
(c2 (org-table-get i2 j2)))
(org-table-put i1 j1 c2)
(org-table-put i2 j2 c1)
(org-table-align)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">org-table-move-single-cell</span> (direction)
<span style="color: #cd6600;">"Move the current cell in a cardinal direction according to the</span>
<span style="color: #cd6600;"> parameter symbol: 'up 'down 'left 'right. Swaps contents of</span>
<span style="color: #cd6600;"> adjacent cell with current one."</span>
(<span style="color: #0000ff;">unless</span> (org-at-table-p)
(<span style="color: #ff0000; font-weight: bold;">error</span> <span style="color: #ff0000;">"No table at point"</span>))
(<span style="color: #0000ff;">let</span> ((di 0) (dj 0))
(<span style="color: #0000ff;">cond</span> ((equal direction <span style="color: #ff00ff;">'up</span>) (<span style="color: #0000ff;">setq</span> di -1))
((equal direction <span style="color: #ff00ff;">'down</span>) (<span style="color: #0000ff;">setq</span> di +1))
((equal direction <span style="color: #ff00ff;">'left</span>) (<span style="color: #0000ff;">setq</span> dj -1))
((equal direction <span style="color: #ff00ff;">'right</span>) (<span style="color: #0000ff;">setq</span> dj +1))
(t (<span style="color: #ff0000; font-weight: bold;">error</span> <span style="color: #ff0000;">"Not a valid direction, must be up down left right"</span>)))
(<span style="color: #0000ff;">let*</span> ((i1 (org-table-current-line))
(j1 (org-table-current-column))
(i2 (+ i1 di))
(j2 (+ j1 dj)))
(org-table-swap-cells i1 j1 i2 j2)
(org-table-goto-line i2)
(org-table-goto-column j2))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">org-table-move-single-cell-up</span> ()
<span style="color: #cd6600;">"Move a single cell up in a table; swap with anything in target cell"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-move-single-cell <span style="color: #ff00ff;">'up</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">org-table-move-single-cell-down</span> ()
<span style="color: #cd6600;">"Move a single cell down in a table; swap with anything in target cell"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-move-single-cell <span style="color: #ff00ff;">'down</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">org-table-move-single-cell-left</span> ()
<span style="color: #cd6600;">"Move a single cell left in a table; swap with anything in target cell"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-move-single-cell <span style="color: #ff00ff;">'left</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">org-table-move-single-cell-right</span> ()
<span style="color: #cd6600;">"Move a single cell right in a table; swap with anything in target cell"</span>
(<span style="color: #0000ff;">interactive</span>)
(org-table-move-single-cell <span style="color: #ff00ff;">'right</span>))
</pre>
</div>
<p>
actual org table config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">with-eval-after-load</span> <span style="color: #ff0000;">"org"</span>
(add-hook <span style="color: #ff00ff;">'org-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c t l"</span>) <span style="color: #ff00ff;">'tvd-copy-org-table-col</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c t r"</span>) <span style="color: #ff00ff;">'tvd-copy-org-table-row</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c t c"</span>) <span style="color: #ff00ff;">'tvd-copy-org-table-cell</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;left&gt;"</span>) <span style="color: #ff00ff;">'org-table-move-single-cell-left</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;right&gt;"</span>) <span style="color: #ff00ff;">'org-table-move-single-cell-right</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;up&gt;"</span>) <span style="color: #ff00ff;">'org-table-move-single-cell-up</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-M-&lt;down&gt;"</span>) <span style="color: #ff00ff;">'org-table-move-single-cell-down</span>))))
</pre>
</div>
<p>
eval-after-load 'orgtbl doesn't work
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'orgtbl-mode-hook</span> '(<span style="color: #0000ff;">lambda</span> ()
(define-key orgtbl-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c t l"</span>) <span style="color: #ff00ff;">'tvd-copy-org-table-col</span>)
(define-key orgtbl-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c t r"</span>) <span style="color: #ff00ff;">'tvd-copy-org-table-row</span>)
(define-key orgtbl-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c t c"</span>) <span style="color: #ff00ff;">'tvd-copy-org-table-cell</span>)))
</pre>
</div>
<p>
integers, reals, positives, set via custom
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> org-table-number-regexp <span style="color: #ff0000;">"^[-+]?</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[0-9]*\\.[0-9]+</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">[0-9]+\\.?[0-9]*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">$"</span>)
</pre>
</div>
<p>
table hydras, maybe better than aliases?!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defhydra</span> hydra-org-tables (<span style="color: #8a2be2;">:color</span> blue)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">^Sort by^ ^Transform to^ ^Copy/Del what^ ^Modify^ ^Outside Org^</span>
<span style="color: #cd6600;">^^^^^^^^-----------------------------------------------------------------------------------------------------------------------</span>
<span style="color: #cd6600;">_sa_: alphanumeric _tc_: CSV _cl_: Copy Column (C-c t l) _ic_: Insert Column _ot_: Table to Org Mode</span>
<span style="color: #cd6600;">_sA_: -alphanumeric _te_: Excel _cr_: Copy Row (C-c t r) _ir_: Insert Row _oe_: Enable Org-Tbl Mode</span>
<span style="color: #cd6600;">_si_: ip _tl_: Latex _cc_: Copy Cell (C-c t c) _il_: Insert Line _oc_: Turn region to columns</span>
<span style="color: #cd6600;">_sI_: -ip _th_: HTML _dd_: Delete Cell _tr_: Transpose Table</span>
<span style="color: #cd6600;">_sn_: numeric _tt_: Tab _dc_: Delete Column _mr_: Move Cell right</span>
<span style="color: #cd6600;">_sN_: -numeric _ta_: Aligned _dr_: Delete Row _ml_: Move Cell left</span>
<span style="color: #cd6600;">_st_: time ^^ _kr_: Kill Row _mu_: Move Cell up</span>
<span style="color: #cd6600;">_sT_: -time ^^ _kc_: Kill Column _md_: Move Cell down _q_: Cancel</span>
<span style="color: #cd6600;">^^^^^^^^-----------------------------------------------------------------------------------------------------------------------</span>
<span style="color: #cd6600;">Reach this hydra with &lt;C-x t&gt;</span>
<span style="color: #cd6600;">^^^^^^^^-----------------------------------------------------------------------------------------------------------------------</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"mr"</span> org-table-move-single-cell-right)
(<span style="color: #ff0000;">"ml"</span> org-table-move-single-cell-left)
(<span style="color: #ff0000;">"mu"</span> org-table-move-single-cell-up)
(<span style="color: #ff0000;">"md"</span> org-table-move-single-cell-down)
(<span style="color: #ff0000;">"sa"</span> sort-table-alphanumeric nil)
(<span style="color: #ff0000;">"sA"</span> sort-table-alphanumeric-desc nil)
(<span style="color: #ff0000;">"si"</span> sort-table-ip nil)
(<span style="color: #ff0000;">"sI"</span> sort-table-ip-desc nil)
(<span style="color: #ff0000;">"sn"</span> sort-table-numeric nil)
(<span style="color: #ff0000;">"sN"</span> sort-table-numeric-desc nil)
(<span style="color: #ff0000;">"st"</span> sort-table-time nil)
(<span style="color: #ff0000;">"sT"</span> sort-table-time-desc nil)
(<span style="color: #ff0000;">"tc"</span> table-to-csv nil)
(<span style="color: #ff0000;">"te"</span> table-to-excel nil)
(<span style="color: #ff0000;">"tl"</span> table-to-latex nil)
(<span style="color: #ff0000;">"th"</span> table-to-html nil)
(<span style="color: #ff0000;">"tt"</span> table-to-csv-tab nil)
(<span style="color: #ff0000;">"ta"</span> table-to-aligned nil)
(<span style="color: #ff0000;">"cl"</span> tvd-copy-org-table-col nil)
(<span style="color: #ff0000;">"cr"</span> tvd-copy-org-table-row nil)
(<span style="color: #ff0000;">"cc"</span> tvd-copy-org-table-cell nil)
(<span style="color: #ff0000;">"dd"</span> org-table-blank-field nil)
(<span style="color: #ff0000;">"dr"</span> tvd-del-org-table-row nil)
(<span style="color: #ff0000;">"dc"</span> tvd-del-org-table-col nil)
(<span style="color: #ff0000;">"kc"</span> org-table-delete-column nil)
(<span style="color: #ff0000;">"kr"</span> org-table-kill-row nil)
(<span style="color: #ff0000;">"ic"</span> org-table-insert-column nil)
(<span style="color: #ff0000;">"ir"</span> org-table-insert-row nil)
(<span style="color: #ff0000;">"il"</span> org-table-hline-and-move nil)
(<span style="color: #ff0000;">"tr"</span> org-table-transpose-table-at-point nil)
(<span style="color: #ff0000;">"ot"</span> tablify nil)
(<span style="color: #ff0000;">"oe"</span> orgtbl-mode nil)
(<span style="color: #ff0000;">"oc"</span> align-repeat nil)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
</pre>
</div>
<p>
allow me to insert org tables everywhere on request
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'table</span> <span style="color: #ff00ff;">'hydra-org-tables</span>/body)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x t"</span>) <span style="color: #ff00ff;">'hydra-org-tables</span>/body)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgb4fd415" class="outline-4">
<h4 id="orgb4fd415"><span class="section-number-4">6.4.8</span> org mode slideshows</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-8">
<p>
Making presentations within emacs with org mode is cool as well.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'org-present</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'darkroom</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">hides distractions</span>
</pre>
</div>
<p>
showtime helpers
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">slide-return-to-present</span> ()
<span style="color: #cd6600;">"wherever we are, go back to slideshow"</span>
(<span style="color: #0000ff;">interactive</span>)
(switch-to-buffer-other-window <span style="color: #ff0000;">"*slide*"</span>)
(delete-other-windows))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">slide-split-to-past</span> ()
<span style="color: #cd6600;">"split slide show and show previous buffer next to it"</span>
(<span style="color: #0000ff;">interactive</span>)
(split-window-horizontally)
(other-window 1)
(<span style="color: #0000ff;">if</span> (get-buffer <span style="color: #ff0000;">"*eshell*"</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">if there's no eshell running, start it, otherwise switch to it</span>
(switch-to-buffer <span style="color: #ff0000;">"*eshell*"</span>)
(eshell)))
</pre>
</div>
<p>
org present config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"org-present"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'org-present-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(org-present-big)
(org-display-inline-images)
(org-present-hide-cursor)
(org-present-read-only)
<span style="color: #006400;">;; </span><span style="color: #006400;">some opticals</span>
(<span style="color: #0000ff;">setq</span> org-hide-emphasis-markers t)
(font-lock-add-keywords <span style="color: #ff00ff;">'org-mode</span>
'((<span style="color: #ff0000;">"^ +</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[-*]</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;"> "</span>
(0 (<span style="color: #0000ff;">prog1</span> () (compose-region (match-beginning 1) (match-end 1) <span style="color: #ff0000;">"&#8226;"</span>))))))
<span style="color: #006400;">;; </span><span style="color: #006400;">keys</span>
(define-key org-present-mode-keymap [down] <span style="color: #ff00ff;">'org-present-next</span>)
(define-key org-present-mode-keymap [up] <span style="color: #ff00ff;">'org-present-prev</span>)
(define-key org-present-mode-keymap (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) <span style="color: #ff00ff;">'org-present-quit</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c p"</span>) <span style="color: #ff00ff;">'slide-return-to-present</span>) <span style="color: #006400;">; </span><span style="color: #006400;">used inside eshell to return to slide</span>
(define-key org-present-mode-keymap (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"s"</span>) <span style="color: #ff00ff;">'slide-split-to-past</span>)
(<span style="color: #0000ff;">setq</span> current-buffer (buffer-name)) <span style="color: #006400;">; </span><span style="color: #006400;">remember slide buffer name</span>
(rename-buffer <span style="color: #ff0000;">"*slide*"</span>)
<span style="color: #006400;">;;</span><span style="color: #006400;">(darkroom-tentative-mode)</span>
))
(add-hook <span style="color: #ff00ff;">'org-present-mode-quit-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(org-present-small)
(org-remove-inline-images)
(org-present-show-cursor)
(org-present-read-write)
(<span style="color: #0000ff;">setq</span> org-hide-emphasis-markers nil)
(rename-buffer current-buffer)
(global-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c p"</span>))
<span style="color: #006400;">;;</span><span style="color: #006400;">(darkroom-tentative-mode)</span>
))))
</pre>
</div>
<p>
Will be inserted as first help slide in a slide show
(edit table in org-mode!)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">slide-header</span> (prefix)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"P"</span>)
(<span style="color: #0000ff;">save-excursion</span>
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> prefix nil)
()
(goto-char (point-min)))
(insert <span style="color: #ff0000;">"\n* ORG-MODE slide show commands</span>
<span style="color: #ff0000;"> | Key | Command |</span>
<span style="color: #ff0000;"> +-------+------------------------------------------------------------+</span>
<span style="color: #ff0000;"> | C-p | start slide show |</span>
<span style="color: #ff0000;"> | q | stop slide show |</span>
<span style="color: #ff0000;"> | s | slit window and switchto or start eshell |</span>
<span style="color: #ff0000;"> | C-c p | while in split mode, return to full screen slide show |</span>
<span style="color: #ff0000;"> | C-c r | enter window resize mode, use cursor keys, &lt;ret&gt; to finish |</span>
<span style="color: #ff0000;"> | C-- | (CTRL and minus) shrink font size |</span>
<span style="color: #ff0000;"> | C-+ | (CTRL and plus) increase font size |</span>
<span style="color: #ff0000;">"</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org0dd6e1f" class="outline-4">
<h4 id="org0dd6e1f"><span class="section-number-4">6.4.9</span> outshine mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-9">
<p>
I maintain my emacs config with outshine mode. It works a lot like
org mode, but I still have a normal emacs lisp buffer, which I can
use directly without any conversion beforehand and which works if
outshine is not installed. Also I thing "literal programming" is
bullshit.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'outshine</span>)
</pre>
</div>
<p>
Generate an alist of all headings with each position in buffer and
use this later to jump to those positions with IDO.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(make-variable-buffer-local <span style="color: #ff00ff;">'tvd-headings</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outshine-get-level</span> (heading)
<span style="color: #cd6600;">"Return level of HEADING as number, or nil"</span>
(<span style="color: #0000ff;">if</span> (string-match <span style="color: #ff0000;">" </span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">*+</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;"> "</span> heading) <span style="color: #006400;">; </span><span style="color: #006400;">normal outline heading</span>
(length (match-string 1 heading))
(<span style="color: #0000ff;">when</span> (string-match <span style="color: #ff0000;">"^;;</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">;+</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;"> "</span> heading) <span style="color: #006400;">; </span><span style="color: #006400;">else look for elisp heading</span>
(length (match-string 1 heading)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outshine-cl-heading</span> (heading)
(<span style="color: #0000ff;">let</span> ((regex (cadar outshine-imenu-preliminary-generic-expression)))
(<span style="color: #0000ff;">when</span> (string-match regex heading)
(match-string-no-properties 1 heading))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outshine-parse-headings</span> ()
<span style="color: #cd6600;">"extract outshine headings of current buffer"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((line nil))
(<span style="color: #0000ff;">save-excursion</span>
(<span style="color: #0000ff;">setq</span> tvd-headings ())
(beginning-of-buffer)
(<span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">not</span> (eobp))
(<span style="color: #0000ff;">setq</span> line (tvd-get-line))
(<span style="color: #0000ff;">when</span> (outline-on-heading-p t)
(add-to-list <span style="color: #ff00ff;">'tvd-headings</span> (cons (tvd-outshine-cl-heading line) (point))))
(forward-line)))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outshine-sparse-tree</span> ()
<span style="color: #cd6600;">"expand outline tree from current position as sparse tree"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((done nil)
(pos (point))
(tree (list (list (point) 5)))
(l 0))
(<span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">not</span> done)
(outline-up-heading 1)
(<span style="color: #0000ff;">setq</span> l (tvd-outshine-get-level (tvd-get-line)))
(add-to-list <span style="color: #ff00ff;">'tree</span> (list (point) l))
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">eq</span> l 1)
(<span style="color: #0000ff;">setq</span> done t)))
(outline-hide-other)
(<span style="color: #0000ff;">dolist</span> (pos tree)
(goto-char (<span style="color: #0000ff;">car</span> pos))
(outline-cycle))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outshine-jump</span> ()
<span style="color: #cd6600;">"jump to an outshine heading with IDO prompt,</span>
<span style="color: #cd6600;">update heading list if neccessary."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((heading nil))
(<span style="color: #0000ff;">if</span> (string= <span style="color: #ff0000;">""</span> outshine-normalized-outline-regexp-base)
(call-interactively <span style="color: #ff00ff;">'imenu</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">use imenu outside outshine</span>
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">or</span> (<span style="color: #0000ff;">not</span> tvd-headings)
(buffer-modified-p))
(tvd-outshine-parse-headings))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> tvd-headings)
(message <span style="color: #ff0000;">"Could not parse headings"</span>)
(<span style="color: #0000ff;">setq</span> heading (ido-completing-read
<span style="color: #ff0000;">"Jump to heading: "</span>
(tvd-alist-keys tvd-headings)))
(<span style="color: #0000ff;">when</span> heading
(show-all)
(goto-char (<span style="color: #0000ff;">cdr</span> (assoc heading tvd-headings)))
(tvd-outshine-sparse-tree))))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outshine-end-of-section</span> ()
<span style="color: #cd6600;">"Jump to the end of an outshine section."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((end))
(outline-show-subtree)
(<span style="color: #0000ff;">save-excursion</span>
(outline-next-heading)
(<span style="color: #0000ff;">when</span> (outline-on-heading-p)
(backward-paragraph))
(<span style="color: #0000ff;">setq</span> end (point)))
(goto-char end)))
</pre>
</div>
<p>
outshine mode config (inside outline mode)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"outline"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'outline-minor-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'j</span> <span style="color: #ff00ff;">'tvd-outshine-jump</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'jump</span> <span style="color: #ff00ff;">'tvd-outshine-jump</span>)
(define-key outline-minor-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-j"</span>) <span style="color: #ff00ff;">'tvd-outshine-jump</span>)
(<span style="color: #0000ff;">setq</span> outshine-org-style-global-cycling-at-bob-p t
outshine-use-speed-commands t
outshine-speed-commands-user
(<span style="color: #0000ff;">quote</span> (
(<span style="color: #ff0000;">"v"</span> . outshine-narrow-to-subtree)
(<span style="color: #ff0000;">"q"</span> . widen)
(<span style="color: #ff0000;">"e"</span> . tvd-outshine-end-of-section))))))))
</pre>
</div>
<p>
Narrowing now works within the headline rather than requiring to be on it
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(advice-add <span style="color: #ff00ff;">'outshine-narrow-to-subtree</span> <span style="color: #8a2be2;">:before</span>
(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args) (<span style="color: #0000ff;">unless</span> (outline-on-heading-p t)
(outline-previous-visible-heading 1))))
</pre>
</div>
<p>
convert outshine buffer to org buffer using outorg, which is part
of outshine.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">outshine-to-org</span> ()
(<span style="color: #0000ff;">interactive</span>)
(outorg-convert-to-org)
(org-mode))
</pre>
</div>
<p>
I use this to generate a HTML version of my emacs config for
posting online, which makes it way easier to read.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">outshine-to-html</span> (file)
(<span style="color: #0000ff;">interactive</span>
(list
(read-file-name <span style="color: #ff0000;">"HTML output file: "</span>
(expand-file-name <span style="color: #ff0000;">"~/D/github/dot-emacs"</span>)
<span style="color: #ff0000;">"emacs.html"</span>)))
(<span style="color: #0000ff;">let</span> ((B (current-buffer)))
(<span style="color: #0000ff;">with-temp-buffer</span>
(insert-buffer-substring B)
<span style="color: #006400;">;; </span><span style="color: #006400;">remove 'sk spacings for smaller &lt;pre&gt;'s</span>
(tvd-replace-all <span style="color: #ff0000;">")\s*;"</span> <span style="color: #ff0000;">") ;"</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">highlight at least a little</span>
(tvd-replace-all <span style="color: #ff0000;">"/</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #ff0000;">/"</span> <span style="color: #ff0000;">"//</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #ff0000;">//"</span>)
(emacs-lisp-mode)
(outshine-to-org)
(org-export-to-file <span style="color: #ff00ff;">'html</span> file))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">export</span> (cmessage)
<span style="color: #cd6600;">"Export .emacs to git, do not use."</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">/</span><span style="color: #ff0000; background-color: #ffff00; font-weight: bold; text-decoration: underline;">FIXME</span><span style="color: #006400;">/: generate version number, add last changelog to git</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"sEnter Commit Message: "</span>)
(outshine-to-html <span style="color: #ff0000;">"~/D/github/dot-emacs/emacs.html"</span>)
(shell-command <span style="color: #ff0000;">"cp ~/.emacs ~/D/github/dot-emacs/"</span>)
(shell-command (format <span style="color: #ff0000;">"cd ~/D/github/dot-emacs &amp;&amp; git ci '%s' .emacs emacs.html"</span> cmessage))
(shell-command <span style="color: #ff0000;">"cd ~/D/github/dot-emacs &amp;&amp; git push"</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgaacc093" class="outline-4">
<h4 id="orgaacc093"><span class="section-number-4">6.4.10</span> outline mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-10">
<p>
I use the very same cycle style as in org mode: when on a heading,
hide it, jump to next heading on the same level and expand that (or
vice versa). however, when NOT on a heading behave as loved: jump
paragraphs.
</p>
<p>
Note, that this also affects outshine mode, since that inherits
from outline.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outline-left-or-level-up</span>()
<span style="color: #cd6600;">"jump one word to the left if not on a heading,</span>
<span style="color: #cd6600;">otherwise fold current level and jump one level up."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (outline-on-heading-p)
(<span style="color: #0000ff;">progn</span>
(hide-subtree)
(outline-up-heading 1))
(left-word)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outline-heading-up</span>()
<span style="color: #cd6600;">"fold current heading, jump one level up and unfold it"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (outline-on-heading-p))
(backward-paragraph)
(hide-subtree)
(outline-backward-same-level 1)
(outline-cycle)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outline-heading-down</span>()
<span style="color: #cd6600;">"fold current heading, jump one level down and unfold it"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (outline-on-heading-p))
(forward-paragraph)
(hide-subtree)
(outline-forward-same-level 1)
(outline-cycle)))
</pre>
</div>
<p>
unused, see tvd-outshine-jump
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-outline-jump</span> (part)
<span style="color: #cd6600;">"Jump interactively to next header containing PART using search."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"Mjump to: "</span>)
(<span style="color: #0000ff;">let</span> ((done nil)
(pwd (point)))
(beginning-of-buffer)
(outline-show-all)
(<span style="color: #0000ff;">when</span> (re-search-forward (format <span style="color: #ff0000;">"^;; \\*+.*%s"</span> part) (point-max) t)
(<span style="color: #0000ff;">when</span> (outline-on-heading-p)
(beginning-of-line)
(<span style="color: #0000ff;">setq</span> done t)))
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">not</span> done)
(message (format <span style="color: #ff0000;">"no heading with '%s' found"</span> part))
(goto-char pwd))))
</pre>
</div>
<p>
outline mode config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"outline"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'outline-minor-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
<span style="color: #006400;">;; </span><span style="color: #006400;">narrowing, we use outshine functions, it's loaded anyway</span>
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'n</span> <span style="color: #ff00ff;">'outshine-narrow-to-subtree</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'w</span> <span style="color: #ff00ff;">'widen</span>)
(define-key outline-minor-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-up&gt;"</span>) <span style="color: #ff00ff;">'tvd-outline-heading-up</span>)
(define-key outline-minor-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-down&gt;"</span>) <span style="color: #ff00ff;">'tvd-outline-heading-down</span>)
<span style="color: #006400;">;;</span><span style="color: #006400;">(define-key outline-minor-mode-map (kbd "&lt;C-left&gt;") 'tvd-outline-left-or-level-up)</span>
))))
</pre>
</div>
<p>
orange fringe when narrowed
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(advice-add <span style="color: #ff00ff;">'outshine-narrow-to-subtree</span> <span style="color: #8a2be2;">:after</span>
'(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args)
(set-face-attribute <span style="color: #ff00ff;">'fringe</span> nil <span style="color: #8a2be2;">:background</span> tvd-fringe-narrow-bg)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org9cce2a1" class="outline-4">
<h4 id="org9cce2a1"><span class="section-number-4">6.4.11</span> narrowing (no mode but fits here)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-11">
<p>
I use narrowing quite frequently, so here are some enhancements.
</p>
<p>
easier narrowing with Indirect Buffers
Source: <a href="https://www.emacswiki.org/emacs/NarrowIndirect3">emacswiki</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'narrow-indirect</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'nf</span> <span style="color: #ff00ff;">'ni-narrow-to-defun-indirect-other-window</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'nr</span> <span style="color: #ff00ff;">'ni-narrow-to-region-indirect-other-window</span>)
</pre>
</div>
<p>
I like to have an orange fringe background when narrowing is
active, since I forget that it is in effect otherwise sometimes.
</p>
<p>
via <a href="https://emacs.stackexchange.com/questions/33288/how-to-find-out-if-narrow-to-region-has-been-called-within-save-restriction">stackoverflow</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-narrowed-fringe-status</span> ()
<span style="color: #cd6600;">"Make the fringe background reflect the buffer's narrowing status."</span>
(set-face-attribute
<span style="color: #ff00ff;">'fringe</span> nil <span style="color: #8a2be2;">:background</span> (<span style="color: #0000ff;">if</span> (buffer-narrowed-p)
tvd-fringe-narrow-bg
nil)))
(add-hook <span style="color: #ff00ff;">'post-command-hook</span> <span style="color: #ff00ff;">'tvd-narrowed-fringe-status</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgef20fc9" class="outline-4">
<h4 id="orgef20fc9"><span class="section-number-4">6.4.12</span> ANSI-TERM (inferior shells/interpreters and REPLs)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-12">
<p>
I use ansi term for inferior shells only.
</p>
<p>
via <a href="http://echosa.github.io/blog/2012/06/06/improving-ansi-term/">echosa</a>
</p>
<p>
kill buffer when done
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defadvice</span> <span style="color: #9932cc;">term-sentinel</span> (around tvd-advice-term-sentinel (proc msg))
(<span style="color: #0000ff;">if</span> (memq (process-status proc) '(<span style="color: #ff0000; font-weight: bold;">signal</span> exit))
(<span style="color: #0000ff;">let</span> ((buffer (process-buffer proc)))
ad-do-it
(kill-buffer buffer))
ad-do-it))
(ad-activate <span style="color: #ff00ff;">'term-sentinel</span>)
</pre>
</div>
<p>
force utf8
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-term-use-utf8</span> ()
(set-buffer-process-coding-system <span style="color: #ff00ff;">'utf-8-unix</span> <span style="color: #ff00ff;">'utf-8-unix</span>))
(add-hook <span style="color: #ff00ff;">'term-exec-hook</span> <span style="color: #ff00ff;">'tvd-term-use-utf8</span>)
</pre>
</div>
<p>
make C-y work
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-term-paste</span> (<span style="color: #483d8b;">&amp;optional</span> string)
(<span style="color: #0000ff;">interactive</span>)
(process-send-string
(get-buffer-process (current-buffer))
(<span style="color: #0000ff;">if</span> string string (current-kill 0))))
</pre>
</div>
<p>
put all term hooks in here
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-term-hook</span> ()
(goto-address-mode)
(define-key term-raw-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-y"</span>) <span style="color: #ff00ff;">'tvd-term-paste</span>)
(define-key term-raw-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-d"</span>) <span style="color: #ff00ff;">'kill-this-buffer</span>)
(define-key term-raw-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-d"</span>) <span style="color: #ff00ff;">'kill-this-buffer</span>)
(define-key term-raw-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-l"</span>) <span style="color: #ff00ff;">'term-line-mode</span>)
(define-key term-raw-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-k"</span>)
(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">interactive</span>)
(term-send-raw-string <span style="color: #ff0000;">"\C-k"</span>)
(kill-line))))
(add-hook <span style="color: #ff00ff;">'term-mode-hook</span> <span style="color: #ff00ff;">'tvd-term-hook</span>)
</pre>
</div>
<p>
via <a href="https://www.emacswiki.org/emacs/AnsiTermHints#toc4">emacswiki</a>:
Use to supply commandline arguments to ansi-term
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">term-with-args</span> (new-buffer-name cmd <span style="color: #483d8b;">&amp;rest</span> switches)
(<span style="color: #0000ff;">setq</span> term-ansi-buffer-name (concat <span style="color: #ff0000;">"*"</span> new-buffer-name <span style="color: #ff0000;">"*"</span>))
(<span style="color: #0000ff;">setq</span> term-ansi-buffer-name (generate-new-buffer-name term-ansi-buffer-name))
(<span style="color: #0000ff;">setq</span> term-ansi-buffer-name (apply <span style="color: #ff00ff;">'make-term</span> term-ansi-buffer-name cmd nil switches))
(set-buffer term-ansi-buffer-name)
(term-mode)
(term-char-mode)
(message <span style="color: #ff0000;">"Line mode: C-c C-l, Char mode: C-c C-k, Exit: C-c C-d"</span>)
(switch-to-buffer term-ansi-buffer-name))
</pre>
</div>
<p>
finally the inferior REPLs:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">iperl</span> ()
<span style="color: #cd6600;">"interactive perl (via perlbrew if exist or global)"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((perlbrew (expand-file-name <span style="color: #ff0000;">"~/perl5/perlbrew/bin/perlbrew"</span>)))
(<span style="color: #0000ff;">if</span> (file-exists-p perlbrew)
(term-with-args <span style="color: #ff0000;">"*perlbrew-de0*"</span> perlbrew <span style="color: #ff0000;">"exec"</span> <span style="color: #ff0000;">"--"</span> <span style="color: #ff0000;">"perl"</span> <span style="color: #ff0000;">"-de0"</span>)
(term-with-args <span style="color: #ff0000;">"*perl-de0*"</span> <span style="color: #ff0000;">"perl"</span> <span style="color: #ff0000;">"-de0"</span>))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">iruby</span> ()
<span style="color: #cd6600;">"interactive ruby"</span>
(<span style="color: #0000ff;">interactive</span>)
(term-with-args <span style="color: #ff0000;">"*ruby-irb*"</span> <span style="color: #ff0000;">"irb"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">ipython</span> ()
<span style="color: #cd6600;">"interactive python"</span>
(<span style="color: #0000ff;">interactive</span>)
(setenv <span style="color: #ff0000;">"PYTHONSTARTUP"</span> (expand-file-name <span style="color: #ff0000;">"~/.pythonrc"</span>))
(term-with-args <span style="color: #ff0000;">"*python-i*"</span> <span style="color: #ff0000;">"python"</span> <span style="color: #ff0000;">"-i"</span>))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">icalc</span> ()
<span style="color: #cd6600;">"interactive calc"</span>
(<span style="color: #0000ff;">interactive</span>)
(term-with-args <span style="color: #ff0000;">"*calc*"</span> (expand-file-name <span style="color: #ff0000;">"~/bin/calc"</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org4d46d6e" class="outline-4">
<h4 id="org4d46d6e"><span class="section-number-4">6.4.13</span> Puppet</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-13">
<p>
adds hook for .pp files
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'puppet-mode</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org13759ae" class="outline-4">
<h4 id="org13759ae"><span class="section-number-4">6.4.14</span> Novel Mode - Screen Reader</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-14">
<p>
my own emacs screen reader, very handy to read docs on the road.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'novel-mode</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-n"</span>) <span style="color: #ff00ff;">'novel-mode</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgc06e29d" class="outline-4">
<h4 id="orgc06e29d"><span class="section-number-4">6.4.15</span> Macro Math</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-15">
<p>
see <a href="https://github.com/nschum/macro-math.el">macro-math</a>
</p>
<p>
perform elisp evaluation/caluclaton directly in the buffer.
mark something and hit C-x C-0 (which is a reminder to C-x C-= w/o the shift)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(autoload <span style="color: #ff00ff;">'macro-math-eval-and-round-region</span> <span style="color: #ff0000;">"macro-math"</span> t nil)
(autoload <span style="color: #ff00ff;">'macro-math-eval-region</span> <span style="color: #ff0000;">"macro-math"</span> t nil)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-0"</span>) <span style="color: #ff00ff;">'macro-math-eval-region</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgc7adbb3" class="outline-4">
<h4 id="orgc7adbb3"><span class="section-number-4">6.4.16</span> Common-Lisp (SLIME)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-16">
<p>
I'm learing CL with slime, start with M-x slime.
</p>
<p>
INSTALL: (see: <a href="http://www.jonathanfischer.net/modern-common-lisp-on-linux/)">jonathanfischer.net</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> slimehelper (expand-file-name <span style="color: #ff0000;">"~/quicklisp/slime-helper.el"</span>))
(<span style="color: #0000ff;">if</span> (file-exists-p slimehelper)
(<span style="color: #0000ff;">progn</span>
(load slimehelper)
<span style="color: #006400;">;; </span><span style="color: #006400;">Replace "sbcl" with the path to your implementation</span>
(<span style="color: #0000ff;">setq</span> inferior-lisp-program <span style="color: #ff0000;">"sbcl"</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">Stop SLIME's REPL from grabbing DEL,</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">which is annoying when backspacing over a '('</span>
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">override-slime-repl-bindings-with-paredit</span> ()
(define-key slime-repl-mode-map
(read-kbd-macro paredit-backward-delete-key) nil))
(add-hook <span style="color: #ff00ff;">'slime-repl-mode-hook</span> <span style="color: #ff00ff;">'override-slime-repl-bindings-with-paredit</span>)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org8694a3b" class="outline-4">
<h4 id="org8694a3b"><span class="section-number-4">6.4.17</span> INFO Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-17">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'info</span>)
</pre>
</div>
<p>
open an info file somewhere outside %infodir% with info-mode
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">info-find-file</span> (file)
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"f"</span>)
(info-setup file
(pop-to-buffer-same-window
(format <span style="color: #ff0000;">"*info*&lt;%s&gt;"</span>
(file-name-sans-extension
(file-name-nondirectory file))))))
</pre>
</div>
<p>
easier navigation in Info mode, intuitive history back and forth.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"Info"</span>
'(<span style="color: #0000ff;">progn</span>
(define-key Info-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-left&gt;"</span>) <span style="color: #ff00ff;">'Info-history-back</span>)
(define-key Info-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-right&gt;"</span>) <span style="color: #ff00ff;">'Info-history-forward</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'info</span>+)))
</pre>
</div>
<p>
make Info great again!
<a href="http://mbork.pl/2014-12-27_Info_dispatch">based on Marcins</a> info dispatch,
contains (interactive) code from 'info-display-manual for manual selection.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">i</span> (manual)
<span style="color: #cd6600;">"Read documentation for MANUAL in the info system. Name the</span>
<span style="color: #cd6600;">buffer '*Info MANUAL*'. If that buffer is already present, just</span>
<span style="color: #cd6600;">switch to it.</span>
<span style="color: #cd6600;">If MANUAL not given as argument, ask interactively with completion</span>
<span style="color: #cd6600;">to select from a list of installed manuals."</span>
(<span style="color: #0000ff;">interactive</span>
(list
(<span style="color: #0000ff;">progn</span>
(info-initialize)
(ido-completing-read <span style="color: #ff0000;">"Manual name: "</span>
(info--manual-names current-prefix-arg)
nil t))))
(<span style="color: #0000ff;">let</span> ((buffer (format <span style="color: #ff0000;">"*Info %s*"</span> manual)))
(<span style="color: #0000ff;">if</span> (get-buffer buffer)
(switch-to-buffer bufer)
(info manual buffer))))
</pre>
</div>
<p>
from examples, I love this one!, replaces the ? buffer
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key Info-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"?"</span>) #<span style="color: #ff00ff;">'hydra-info</span>/body)
(<span style="color: #0000ff;">defhydra</span> hydra-info (<span style="color: #8a2be2;">:color</span> blue
<span style="color: #8a2be2;">:hint</span> nil)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">Info-mode:</span>
<span style="color: #cd6600;"> ^^_]_ forward (next logical node) ^^_l_ast (&#8592;) _u_p (&#8593;) _f_ollow reference _T_OC</span>
<span style="color: #cd6600;"> ^^_[_ backward (prev logical node) ^^_r_eturn (&#8594;) _m_enu (&#8595;) (C-u for new window) _i_ndex _d_irectory</span>
<span style="color: #cd6600;"> ^^_n_ext (same level only) ^^_H_istory _g_oto (C-u for new window) _,_ next index item _c_opy node name</span>
<span style="color: #cd6600;"> ^^_p_rev (same level only) _&lt;_/_t_op _b_eginning of buffer virtual _I_ndex _C_lone buffer</span>
<span style="color: #cd6600;"> regex _s_earch (_S_ case sensitive) ^^_&gt;_ final _e_nd of buffer ^^ _a_propos</span>
<span style="color: #cd6600;"> _1_ .. _9_ Pick first .. ninth item in the node's menu.</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"]"</span> Info-forward-node nil)
(<span style="color: #ff0000;">"["</span> Info-backward-node nil)
(<span style="color: #ff0000;">"n"</span> Info-next nil)
(<span style="color: #ff0000;">"p"</span> Info-prev nil)
(<span style="color: #ff0000;">"s"</span> Info-search nil)
(<span style="color: #ff0000;">"S"</span> Info-search-case-sensitively nil)
(<span style="color: #ff0000;">"l"</span> Info-history-back nil)
(<span style="color: #ff0000;">"r"</span> Info-history-forward nil)
(<span style="color: #ff0000;">"H"</span> Info-history nil)
(<span style="color: #ff0000;">"t"</span> Info-top-node nil)
(<span style="color: #ff0000;">"&lt;"</span> Info-top-node nil)
(<span style="color: #ff0000;">"&gt;"</span> Info-final-node nil)
(<span style="color: #ff0000;">"u"</span> Info-up nil)
(<span style="color: #ff0000;">"^"</span> Info-up nil)
(<span style="color: #ff0000;">"m"</span> Info-menu nil)
(<span style="color: #ff0000;">"g"</span> Info-goto-node nil)
(<span style="color: #ff0000;">"b"</span> beginning-of-buffer nil)
(<span style="color: #ff0000;">"e"</span> end-of-buffer nil)
(<span style="color: #ff0000;">"f"</span> Info-follow-reference nil)
(<span style="color: #ff0000;">"i"</span> Info-index nil)
(<span style="color: #ff0000;">","</span> Info-index-next nil)
(<span style="color: #ff0000;">"I"</span> Info-virtual-index nil)
(<span style="color: #ff0000;">"T"</span> Info-toc nil)
(<span style="color: #ff0000;">"d"</span> Info-directory nil)
(<span style="color: #ff0000;">"c"</span> Info-copy-current-node-name nil)
(<span style="color: #ff0000;">"C"</span> clone-buffer nil)
(<span style="color: #ff0000;">"a"</span> info-apropos nil)
(<span style="color: #ff0000;">"1"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"2"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"3"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"4"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"5"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"6"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"7"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"8"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"9"</span> Info-nth-menu-item nil)
(<span style="color: #ff0000;">"?"</span> Info-summary <span style="color: #ff0000;">"Info summary"</span>)
(<span style="color: #ff0000;">"h"</span> Info-help <span style="color: #ff0000;">"Info help"</span>)
(<span style="color: #ff0000;">"q"</span> Info-exit <span style="color: #ff0000;">"Info exit"</span>)
(<span style="color: #ff0000;">"C-g"</span> nil <span style="color: #ff0000;">"cancel"</span> <span style="color: #8a2be2;">:color</span> blue))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org05009ac" class="outline-4">
<h4 id="org05009ac"><span class="section-number-4">6.4.18</span> calc et al.</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-18">
<p>
emacs provides 4 ways to calculate:
</p>
<p>
M-x calc:
RPN calc with stack. Enter numbers, when done, operator, enter, etc
heavy duty.
</p>
<p>
provided by calc:
</p>
<pre class="example">
(defun c (expr)
(interactive "Mcalc:")
(message (format "result: %s" (calc-eval expr))))
</pre>
<p>
by calc as well, but with algebraic input, access last result with $
algebraic == 1 +1 / 3. result will stored in kill-ring, use C-y to paste
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'c</span> <span style="color: #ff00ff;">'quick-calc</span>)
</pre>
</div>
<p>
M-x calculator
interactive, simpler than calc, but comprehensive nevertheless, input
is algebraic as well, but last result can be used just as ~/bin/calc
</p>
<p>
lisp can be used to calc as well:
M-x evaluate-expression &lt;ret&gt; (+ 1 2) &lt;ret&gt;
</p>
<p>
or, inferior perl calc: M-x icalc, see above
</p>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org5e61a75" class="outline-4">
<h4 id="org5e61a75"><span class="section-number-4">6.4.19</span> MACROs</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-19">
<p>
help: <a href="https://www.emacswiki.org/emacs/KeyboardMacrosTricks">emacswiki macro tricks</a>.
</p>
<p>
Default keybindings:
start-kbd-macro default binding: C-x ( — Starts recording a keyboard macro.
end-kbd-macro default binding: C-x ) — Ends recording of a keyboard macro.
call-last-kbd-macro default binding: C-x e — Executes the last keyboard macro defined.
</p>
<p>
however, I use <a href="https://github.com/Silex/elmacro">elmacro</a>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'elmacro</span>)
(elmacro-mode)
(<span style="color: #0000ff;">setq</span> tvd-macro-name <span style="color: #ff0000;">"last-macro"</span>)
</pre>
</div>
<p>
ignore stuff
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'elmacro-unwanted-commands-regexps</span> <span style="color: #ff0000;">"^(mouse.*)$"</span>)
(add-to-list <span style="color: #ff00ff;">'elmacro-unwanted-commands-regexps</span> <span style="color: #ff0000;">"^(tvd-start-or-stop-macro)$"</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-get-macro-name</span>()
<span style="color: #cd6600;">"Ask for a macro name, check for duplicates.</span>
<span style="color: #cd6600;">If the given name is already defined, ask again (and again until unique).</span>
<span style="color: #cd6600;">If a buffer with the given name exists, kill it (that is, the buffer is</span>
<span style="color: #cd6600;">there but has not been saved or evaluated yet). Return the name as string."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((done nil)
(name nil)
(mbuf nil)
(err <span style="color: #ff0000;">""</span>))
(<span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">not</span> done)
(<span style="color: #0000ff;">setq</span> name (read-string (format <span style="color: #ff0000;">"%s - enter macro name (last-macro): "</span> err) nil nil <span style="color: #ff0000;">"last-macro"</span>))
(<span style="color: #0000ff;">if</span> (fboundp (intern name))
(<span style="color: #0000ff;">setq</span> err (format <span style="color: #ff0000;">"macro '%s is already defined"</span> name))
(<span style="color: #0000ff;">setq</span> mbuf (format <span style="color: #ff0000;">"* elmacro - %s *"</span> name))
(<span style="color: #0000ff;">if</span> (get-buffer mbuf)
(<span style="color: #0000ff;">with-current-buffer</span> mbuf
(kill-buffer mbuf)))
(<span style="color: #0000ff;">setq</span> done t)))
name))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-get-exec-macro-name</span>()
<span style="color: #cd6600;">"Ask for a macro name to be executed"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((macros ())
(N 1)
(S nil)
(T <span style="color: #ff0000;">""</span>))
(<span style="color: #0000ff;">dolist</span> (entry (<span style="color: #0000ff;">cdr</span> (assoc tvd-macro-file load-history )))
(<span style="color: #0000ff;">setq</span> S (<span style="color: #0000ff;">cdr</span> entry))
(<span style="color: #0000ff;">setq</span> T (symbol-name S))
(<span style="color: #0000ff;">push</span> (list T N) macros)
(<span style="color: #0000ff;">setq</span> N (1+ N)))
(completing-read <span style="color: #ff0000;">"enter macro name: "</span> macros nil t nil)))
</pre>
</div>
<p>
the heart of my elmacro stuff
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-start-or-stop-macro</span>()
<span style="color: #cd6600;">"start macro or stop if started"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> defining-kbd-macro nil)
(<span style="color: #0000ff;">progn</span>
(elmacro-clear-command-history)
(start-kbd-macro nil)
(message <span style="color: #ff0000;">"Recording macro. Finish with &lt;shift-F6&gt; ..."</span>))
(<span style="color: #0000ff;">progn</span>
(call-interactively <span style="color: #ff00ff;">'end-kbd-macro</span>)
(<span style="color: #0000ff;">setq</span> tvd-macro-name (tvd-get-macro-name))
(elmacro-show-last-macro tvd-macro-name)
(message <span style="color: #ff0000;">"Recording done. Execute with &lt;C-F6&gt;, save or &lt;C-x C-e&gt; buffer..."</span>))))
</pre>
</div>
<p>
better than the default function
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-exec-last-macro</span>(<span style="color: #483d8b;">&amp;optional</span> ARG)
<span style="color: #cd6600;">"execute last macro (or ARG, if given) repeatedly after every</span>
<span style="color: #cd6600;">&lt;ret&gt;, abort with C-g or q, and repeat until EOF after pressing a.</span>
<span style="color: #cd6600;">If macro defun is known (i.e. because you evaluated the elmacro buffer</span>
<span style="color: #cd6600;">containing the generated defun), it will be executed. Otherwise the</span>
<span style="color: #cd6600;">last kbd-macro will be executed."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((melm-count 0)
(melm-all nil)
(melm-abort nil)
(melm-beg (eobp))
(melm-code (<span style="color: #0000ff;">or</span> ARG tvd-macro-name)))
(<span style="color: #0000ff;">if</span> (eobp)
(<span style="color: #0000ff;">if</span> (yes-or-no-p <span style="color: #ff0000;">"(point) is at end of buffer. Jump to top?"</span>)
(goto-char (point-min))))
(<span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">and</span> (<span style="color: #0000ff;">not</span> melm-abort)
(<span style="color: #0000ff;">not</span> (eobp)))
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">not</span> melm-all)
(message (concat
(format
<span style="color: #ff0000;">"Executing last macro '%s (%d). Keys:\n"</span> melm-code melm-count)
<span style="color: #ff0000;">"&lt;enter&gt; repeat once\n"</span>
<span style="color: #ff0000;">"a repeat until EOF\n"</span>
<span style="color: #ff0000;">"e enter macro name to execute\n"</span>
<span style="color: #ff0000;">"&lt;C-g&gt; or q abort ..\n "</span>))
(<span style="color: #0000ff;">setq</span> K (read-event))
(<span style="color: #0000ff;">cond</span> ((<span style="color: #0000ff;">or</span> (<span style="color: #0000ff;">eq</span> K <span style="color: #ff00ff;">'return</span>) (<span style="color: #0000ff;">eq</span> K <span style="color: #ff00ff;">'C-f6</span>)) t)
((equal (char-to-string K) <span style="color: #ff0000;">"q"</span>) (<span style="color: #0000ff;">setq</span> melm-abort t))
((equal (char-to-string K) <span style="color: #ff0000;">"a"</span>) (message <span style="color: #ff0000;">"Repeating until EOF"</span>)(<span style="color: #0000ff;">setq</span> melm-all t))
((equal (char-to-string K) <span style="color: #ff0000;">"e"</span>) (<span style="color: #0000ff;">setq</span> tvd-macro-name (tvd-get-exec-macro-name)))
(t (<span style="color: #0000ff;">setq</span> melm-abort t))))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> melm-abort)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">if</span> (fboundp (intern melm-code))
(call-interactively (intern melm-code))
(call-interactively <span style="color: #ff00ff;">'call-last-kbd-macro</span>))
(<span style="color: #0000ff;">setq</span> melm-count (1+ melm-count)))))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">and</span> (<span style="color: #0000ff;">eq</span> melm-count 0) (<span style="color: #0000ff;">eq</span> (point) (point-max)))
(message <span style="color: #ff0000;">"(point) is at end of buffer, aborted"</span>)
(message (format <span style="color: #ff0000;">"executed '%s %d times"</span> melm-code melm-count)))))
</pre>
</div>
<p>
My macro recording workflow:
</p>
<ul class="org-ul">
<li>shift-F6</li>
<li>&#x2026; do things &#x2026;</li>
<li>shift-F6 again</li>
<li>enter a name</li>
<li>a new buffer with macro defun appears</li>
<li>C-x C-e evals it</li>
<li>C-F6 (repeatedly) executes it.</li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;f6&gt;"</span>) <span style="color: #ff00ff;">'tvd-start-or-stop-macro</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-f6&gt;"</span>) <span style="color: #ff00ff;">'tvd-exec-last-macro</span>)
</pre>
</div>
<p>
I use my own macro file
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-macro-file (concat tvd-lisp-dir <span style="color: #ff0000;">"/macros.el"</span>))
</pre>
</div>
<p>
but only load if in use
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (file-exists-p tvd-macro-file)
(load-file tvd-macro-file))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-macro-store</span>()
<span style="color: #cd6600;">"store current macro to emacs config"</span>
(<span style="color: #0000ff;">interactive</span>)
(copy-region-as-kill (point-min) (point-max))
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (get-buffer <span style="color: #ff0000;">"macros.el"</span>))
(find-file tvd-macro-file))
(<span style="color: #0000ff;">with-current-buffer</span> <span style="color: #ff0000;">"macros.el"</span>
(goto-char (point-max))
(newline)
(insert <span style="color: #ff0000;">";;"</span>)
(newline)
(insert (format <span style="color: #ff0000;">";; elmacro added on %s"</span> (current-time-string)))
(newline)
(yank)
(newline)
(save-buffer))
(switch-to-buffer nil)
(delete-window))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'ms</span> <span style="color: #ff00ff;">'tvd-macro-store</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-macro-gen-repeater-and-save</span>()
<span style="color: #cd6600;">"generate repeater and save the defun's</span>
<span style="color: #cd6600;">Runs when (point) is at 0,0 of generated</span>
<span style="color: #cd6600;">defun."</span>
(next-line)
(goto-char (point-max))
(newline)
(insert (format <span style="color: #ff0000;">"(defun %s-repeat()\n"</span> tvd-macro-name))
(insert <span style="color: #ff0000;">" (interactive)\n"</span>)
(insert (format <span style="color: #ff0000;">" (tvd-exec-last-macro \"%s\"))\n"</span> tvd-macro-name))
(newline)
(eval-buffer)
(tvd-macro-store))
(advice-add <span style="color: #ff00ff;">'elmacro-show-defun</span> <span style="color: #8a2be2;">:after</span> '(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args)
(tvd-macro-gen-repeater-and-save)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org6ce8c6d" class="outline-4">
<h4 id="org6ce8c6d"><span class="section-number-4">6.4.20</span> EWW browser stuff</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-20">
<p>
Emacs has a builtin browser, which is not too bad.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'eww</span>)
</pre>
</div>
<p>
see also: shr-render-[buffer|region] !
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">eww-render-current-buffer</span> ()
<span style="color: #cd6600;">"Render HTML in the current buffer with EWW"</span>
(<span style="color: #0000ff;">interactive</span>)
(beginning-of-buffer)
(eww-display-html <span style="color: #ff00ff;">'utf8</span> (buffer-name)))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'render-html</span> <span style="color: #ff00ff;">'eww-render-current-buffer</span>)
</pre>
</div>
<p>
eww config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'eww-mode-hook</span> #<span style="color: #ff00ff;">'toggle-word-wrap</span>)
(add-hook <span style="color: #ff00ff;">'eww-mode-hook</span> #<span style="color: #ff00ff;">'visual-line-mode</span>)
</pre>
</div>
<p>
custom short commands, see ? for the defaults
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key eww-mode-map <span style="color: #ff0000;">"o"</span> <span style="color: #ff00ff;">'eww</span>) <span style="color: #006400;">; </span><span style="color: #006400;">aka other page</span>
(define-key eww-mode-map <span style="color: #ff0000;">"f"</span> <span style="color: #ff00ff;">'eww-browse-with-external-browser</span>) <span style="color: #006400;">; </span><span style="color: #006400;">aka firefox</span>
(define-key eww-mode-map <span style="color: #ff0000;">"j"</span> <span style="color: #ff00ff;">'next-line</span>)
(define-key eww-mode-map <span style="color: #ff0000;">"r"</span> <span style="color: #ff00ff;">'eww-reload</span>)
(define-key eww-mode-map <span style="color: #ff0000;">"s"</span> <span style="color: #ff00ff;">'shr-save-contents</span>)
(define-key eww-mode-map <span style="color: #ff0000;">"v"</span> <span style="color: #ff00ff;">'eww-view-source</span>)
(define-key eww-mode-map <span style="color: #ff0000;">"b"</span> <span style="color: #ff00ff;">'eww-add-bookmark</span>)
(define-key eww-mode-map <span style="color: #ff0000;">"p"</span> <span style="color: #ff00ff;">'eww-back-url</span>)
(define-key eww-mode-map <span style="color: #ff0000;">"n"</span> <span style="color: #ff00ff;">'eww-forward-url</span>)
</pre>
</div>
<p>
link short commands
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key eww-link-keymap <span style="color: #ff0000;">"c"</span> <span style="color: #ff00ff;">'shr-copy-url</span>)
(define-key eww-link-keymap <span style="color: #ff0000;">"s"</span> <span style="color: #ff00ff;">'shr-save-contents</span>)
</pre>
</div>
<p>
<i>FIXME</i>: latest GIT version of eww contains 'eww-readable, which
hides menus and distractions! Update emacs.
</p>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org3769139" class="outline-4">
<h4 id="org3769139"><span class="section-number-4">6.4.21</span> Firestarter</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-21">
<p>
experimental: do things on save buffer etc.
Source: <a href="https://github.com/wasamasa/firestarter">firestarter</a>
</p>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgf7b647a" class="outline-4">
<h4 id="orgf7b647a"><span class="section-number-4">6.4.22</span> Tabulated List Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-22">
<p>
built-in, used by many interactive major modes
</p>
<p>
+tablist, which provides many cool features
<a href="https://github.com/politza/tablist">github source</a>
important commands:
</p>
<ul class="org-ul">
<li>&lt; shrink column</li>
<li>&gt; enlarge column</li>
<li>s sort column</li>
<li>/ prefix for filter commands
/ e edit filter, e.g. do not list auto-complete sub-packages in melpa:
/ a ! Package =~ ac- &lt;ret&gt;</li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'tablist</span>)
</pre>
</div>
<p>
we need to kill tablist's binding in order to have ours run (see below)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key tablist-minor-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) nil)
(define-key tablist-minor-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) <span style="color: #ff00ff;">'tvd-close-window</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-close-window</span> ()
(<span style="color: #0000ff;">interactive</span>)
(kill-this-buffer)
(delete-window))
(eval-after-load <span style="color: #ff0000;">"tabulated-list"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'tabulated-list-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(tablist-minor-mode)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"Q"</span>) <span style="color: #ff00ff;">'delete-other-windows</span>)
(hl-line-mode)))))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org415695d" class="outline-4">
<h4 id="org415695d"><span class="section-number-4">6.4.23</span> Help Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-23">
<p>
I even customize help windows! &#x2026; at least a little :)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-close-help</span> ()
(<span style="color: #0000ff;">interactive</span>)
(kill-this-buffer)
(winner-undo))
(eval-after-load <span style="color: #ff0000;">"Help"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'help-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
<span style="color: #006400;">; </span><span style="color: #006400;">doesn' work the way I like</span>
<span style="color: #006400;">;</span><span style="color: #006400;">(local-set-key (kbd "q") 'tvd-close-help)</span>
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) <span style="color: #ff00ff;">'quit-window</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"p"</span>) <span style="color: #ff00ff;">'help-go-back</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"b"</span>) <span style="color: #ff00ff;">'help-go-back</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"n"</span>) <span style="color: #ff00ff;">'help-go-forward</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"f"</span>) <span style="color: #ff00ff;">'help-go-forward</span>)
(<span style="color: #0000ff;">setq</span> help-window-select t)
))))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org095cda7" class="outline-4">
<h4 id="org095cda7"><span class="section-number-4">6.4.24</span> Suggest Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-24">
<p>
<a href="https://github.com/Wilfred/suggest.el">suggest mode</a> is a great
elisp development tool. Execute `M-x suggest' and try it.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'suggest</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">depends on dash, s, f, loop</span>
</pre>
</div>
<p>
I use my own clearing function, since suggest doesn't provide this
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-suggest-reload</span> ()
<span style="color: #cd6600;">"Clear suggest buffer and re-paint it."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((inhibit-read-only t))
(erase-buffer)
(suggest--insert-heading suggest--inputs-heading)
(insert <span style="color: #ff0000;">"\n\n\n"</span>)
(suggest--insert-heading suggest--outputs-heading)
(insert <span style="color: #ff0000;">"\n\n\n"</span>)
(suggest--insert-heading suggest--results-heading)
(insert <span style="color: #ff0000;">"\n"</span>)
(suggest--nth-heading 1)
(forward-line 1)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-suggest-jump</span> ()
<span style="color: #cd6600;">"Jump between input and output suggest buffer."</span>
(<span style="color: #0000ff;">interactive</span>)
(forward-line -1)
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> (line-number-at-pos) 1)
(suggest--nth-heading 2)
(suggest--nth-heading 1))
(forward-line 1))
(eval-after-load <span style="color: #ff0000;">"suggest"</span>
'(<span style="color: #0000ff;">progn</span>
(add-hook <span style="color: #ff00ff;">'suggest-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-l"</span>) <span style="color: #ff00ff;">'tvd-suggest-reload</span>)
(local-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;tab&gt;"</span>) <span style="color: #ff00ff;">'tvd-suggest-jump</span>)))))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgd744fec" class="outline-4">
<h4 id="orgd744fec"><span class="section-number-4">6.4.25</span> Followcursor Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-25">
<p>
<a href="https://github.com/TLINDEN/followcursor-mode">source on github</a>
</p>
<p>
From time to time I need to refactor configs and the like based on
lists. For example in the left window I have a list of bgp peers
and in the right window a config file for all peers which I have to
modify based on current settings. With followcursor-mode I can put
point on an ip address and the line in the config containing this
ip address will be highlighted. If I move on to the next address
the next line on the right will be highlighted.
</p>
<p>
The mode is a work-in-progress&#x2026;
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'followcursor-mode</span>)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org98a039d" class="outline-4">
<h4 id="org98a039d"><span class="section-number-4">6.4.26</span> RCS Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-4-26">
2020-11-26 20:56:59 +01:00
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">rcs-ci-co</span> nil
<span style="color: #cd6600;">"check in check out the file if it is under vc with rcs</span>
<span style="color: #cd6600;"> with a prefix other than 1 only check-in"</span>
(<span style="color: #0000ff;">when</span> (<span style="color: #0000ff;">eq</span> (vc-backend (buffer-file-name)) <span style="color: #ff00ff;">'RCS</span>)
(<span style="color: #0000ff;">if</span> (= args 1)
(<span style="color: #0000ff;">save-window-excursion</span>
(vc-toggle-read-only)
(call-interactively <span style="color: #ff00ff;">'log-edit-done</span>)
(vc-toggle-read-only))
(vc-toggle-read-only))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">rcs-is-under-revision</span> ()
<span style="color: #cd6600;">"Return t in case current buffer is RCS revisioned"</span>
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> (vc-backend (buffer-file-name)) <span style="color: #ff00ff;">'RCS</span>)
<span style="color: #ff0000;">"[X]"</span> <span style="color: #ff0000;">"[ ]"</span>))
</pre>
</div>
<p>
always lock after checkout
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> vc-rcs-checkin-switches <span style="color: #ff0000;">"-l"</span>)
(<span style="color: #0000ff;">defhydra</span> hydra-rcs (<span style="color: #8a2be2;">:color</span> blue)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">RCS revision control. Current buffer %(file-name-nondirectory (buffer-file-name)) is under RCS: %(rcs-is-under-revision).</span>
<span style="color: #cd6600;"> _co_: Checkout (C-x v v)</span>
<span style="color: #cd6600;"> _ci_: Checkin (C-x v v)</span>
<span style="color: #cd6600;"> _d_: Diff (C-x v =)</span>
<span style="color: #cd6600;"> _u_: Undo Changes (C-x v u)</span>
<span style="color: #cd6600;"> _l_: View revision log (C-x v l)</span>
<span style="color: #cd6600;"> _s_: Status (C-x v d)</span>
<span style="color: #cd6600;"> _m_: Merge (C-x v m)</span>
<span style="color: #cd6600;"> _q_: Cancel</span>
<span style="color: #cd6600;">^^^^^^^^---------------------</span>
<span style="color: #cd6600;">Reach this hydra with &lt;C-x R&gt;</span>
<span style="color: #cd6600;">^^^^^^^^---------------------</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"co"</span> rcs-ci-co)
(<span style="color: #ff0000;">"ci"</span> rcs-ci-co)
(<span style="color: #ff0000;">"d"</span> vc-version-diff)
(<span style="color: #ff0000;">"u"</span> vc-revert-buffer)
(<span style="color: #ff0000;">"l"</span> vc-print-log)
(<span style="color: #ff0000;">"s"</span> vc-dir)
(<span style="color: #ff0000;">"m"</span> vc-merge)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x R"</span>) <span style="color: #ff00ff;">'hydra-rcs</span>/body)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgeef2915" class="outline-4">
<h4 id="orgeef2915"><span class="section-number-4">6.4.27</span> Magit</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-27">
2020-09-02 20:44:21 +02:00
<p>
Not much to say about Magit
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">unless</span> tvd-win-home
(<span style="color: #0000ff;">setq</span> tvd-magit-revision <span style="color: #ff0000;">"20170725.1153"</span>)
(add-to-list <span style="color: #ff00ff;">'load-path</span> (concat tvd-lisp-dir (concat <span style="color: #ff0000;">"/magit-"</span> tvd-magit-revision)))
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'magit</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-magit-status</span> ()
<span style="color: #cd6600;">"Always call `</span><span style="color: #cd6600;">magit-status</span><span style="color: #cd6600;">' with prefix arg."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((current-prefix-arg t))
(call-interactively <span style="color: #ff00ff;">'magit-status</span>)))
(<span style="color: #0000ff;">with-eval-after-load</span> <span style="color: #ff00ff;">'info</span>
(info-initialize)
(add-to-list <span style="color: #ff00ff;">'Info-directory-list</span>
(expand-file-name (concat <span style="color: #ff0000;">"~/.emacs.d/lisp/magit-"</span>
tvd-magit-revision
<span style="color: #ff0000;">"/Documentation/"</span>)))
(<span style="color: #0000ff;">setq</span> magit-view-git-manual-method <span style="color: #ff00ff;">'woman</span>))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'git</span> <span style="color: #ff00ff;">'magit-status</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'gitlog</span> <span style="color: #ff00ff;">'magit-log-buffer-file</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">configure magit</span>
(<span style="color: #0000ff;">with-eval-after-load</span> <span style="color: #ff00ff;">'magit</span>
(<span style="color: #0000ff;">dolist</span> (dir (list (expand-file-name <span style="color: #ff0000;">"~/D/github"</span>)
(expand-file-name <span style="color: #ff0000;">"~/dev/git"</span>)))
(<span style="color: #0000ff;">when</span> (file-exists-p dir)
(add-to-list <span style="color: #ff00ff;">'magit-repository-directories</span> (cons dir 1))))
(<span style="color: #0000ff;">setq</span> magit-completing-read-function <span style="color: #ff00ff;">'magit-ido-completing-read</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">use timestamps in log buffers</span>
(<span style="color: #0000ff;">setq</span> magit-log-margin '(t <span style="color: #ff0000;">"%Y-%m-%d "</span> magit-log-margin-width t 18))
<span style="color: #006400;">;; </span><span style="color: #006400;">navigate magit buffers as I do everywhere else, I do not automatically</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">cycle/decycle though, the magit defaults are absolutely sufficient.</span>
(define-key magit-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-down&gt;"</span>) <span style="color: #ff00ff;">'magit-section-forward-sibling</span>)
(define-key magit-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-up&gt;"</span>) <span style="color: #ff00ff;">'magit-section-backward-sibling</span>)
(define-key magit-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;delete&gt;"</span>) <span style="color: #ff00ff;">'magit-delete-thing</span>))
<span style="color: #006400;">;; </span><span style="color: #006400;">one thing though: on startup it bitches about git version, but it</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">works nevertheless. So I disable this specific warning.</span>
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ignore-magit-warnings-if-any</span> ()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">when</span> (get-buffer <span style="color: #ff0000;">"*Warnings*"</span>)
(<span style="color: #0000ff;">with-current-buffer</span> <span style="color: #ff0000;">"*Warnings*"</span>
(goto-char (point-min))
(<span style="color: #0000ff;">when</span> (re-search-forward <span style="color: #ff0000;">"Magit requires Git &gt;="</span>)
(kill-buffer-and-window)))))
(add-hook <span style="color: #ff00ff;">'after-init-hook</span> <span style="color: #ff00ff;">'tvd-ignore-magit-warnings-if-any</span> t)
<span style="color: #006400;">;; </span><span style="color: #006400;">now, THIS is the pure genius me: hit "ls in magit-status buffer</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">and end up in a dired buffer of current repository. The default</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">binding for this is C-M-i, which is not memorizable, while "ls"</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">is. That is, 'l' is a prefix command leading to magit-log-popup</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">and 's' is undefined, which I define here, which then jumps to</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">dired.</span>
(magit-define-popup-action <span style="color: #ff00ff;">'magit-log-popup</span>
?s <span style="color: #ff0000;">"Dired"</span> <span style="color: #ff00ff;">'magit-dired-jump</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">after an exhausting discussion on magit#3139 I use this function</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">to (kind of) switch to another repository from inside magit-status.</span>
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-switch-magit-repo</span> ()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((dir (magit-read-repository)))
(magit-mode-bury-buffer)
(magit-status dir)))
(define-key magit-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C"</span>) <span style="color: #ff00ff;">'tvd-switch-magit-repo</span>)
2020-11-26 20:56:59 +01:00
<span style="color: #006400;">;; </span><span style="color: #006400;">scheisse</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">(require 'magit-gh-pulls)</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">(add-hook 'magit-mode-hook 'turn-on-magit-gh-pulls)</span>
2020-09-02 20:44:21 +02:00
<span style="color: #006400;">;; </span><span style="color: #006400;">via</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">http://manuel-uberti.github.io/emacs/2018/02/17/magit-bury-buffer/:</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">a great enhancement, when closing the magit status buffer, ALL</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">other possibly still remaining magit buffers will be killed as</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">well AND the window setup will be restored.</span>
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-kill-magit-buffers</span>()
<span style="color: #cd6600;">"Restore window setup from before magit and kill all magit buffers."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((buffers (magit-mode-get-buffers)))
(magit-restore-window-configuration)
(mapc #<span style="color: #ff00ff;">'kill-buffer</span> buffers)))
(define-key magit-status-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) #<span style="color: #ff00ff;">'tvd-kill-magit-buffers</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orga69858c" class="outline-4">
<h4 id="orga69858c"><span class="section-number-4">6.4.28</span> Dired</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-28">
2020-09-02 20:44:21 +02:00
<p>
I use dired for two things: from inside magit as a convenient way
to add or remove files from a repository. Or if I want to rename a
bunch of files using search/replace and other editing commands.
</p>
<p>
But as with everything else I use, it must fit and so I managed to
tune this as well.
</p>
<p>
<a href="http://ergoemacs.org/emacs/emacs_dired_tips.html">More Hints</a>
</p>
</div>
2021-05-01 13:15:16 +02:00
<ol class="org-ol"><li><a id="org12b51e7"></a>dired-k<br /><div class="outline-text-5" id="text-6-4-28-1">
2020-09-02 20:44:21 +02:00
<p>
dired-k is k for dired/emacs: it colorizes files and directory by
age, that is, the older the greyer they get. And it displays flags
about the git status of each file, which is really handy.
</p>
<p>
However, it only works with git installed and if enabled stops
dired to work completely. So I define an exception here and don't
load k if there's no git (e.g. on my notebook at work)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">when</span> (string-match <span style="color: #ff0000;">"version"</span> (shell-command-to-string <span style="color: #ff0000;">"git version"</span>))
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'dired-k</span>)
(add-hook <span style="color: #ff00ff;">'dired-initial-position-hook</span> <span style="color: #ff00ff;">'dired-k</span>)
(add-hook <span style="color: #ff00ff;">'dired-after-readin-hook</span> #<span style="color: #ff00ff;">'dired-k-no-revert</span>)
(<span style="color: #0000ff;">setq</span> dired-k-padding 2))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="org801693a"></a>dired-hacks<br /><div class="outline-text-5" id="text-6-4-28-2">
2020-09-02 20:44:21 +02:00
<p>
<a href="https://github.com/Fuco1/dired-hacks">Fuco1s dired-hacks</a> is a
place to find the really cool stuff, I mostly use the filters.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'dired-filter</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dired-quit-or-filter-pop</span> (<span style="color: #483d8b;">&amp;optional</span> arg)
<span style="color: #cd6600;">"Remove a filter from the filter stack. If none left, quit the dired buffer."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"p"</span>)
(<span style="color: #0000ff;">if</span> dired-filter-stack
(dired-filter-pop arg)
(quit-window)))
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'dired-ranger</span>)
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="org5bd4445"></a>dired sort helpers<br /><div class="outline-text-5" id="text-6-4-28-3">
2020-09-02 20:44:21 +02:00
<p>
This sort function by <a href="http://ergoemacs.org/emacs/dired_sort.html">Xah Lee</a>
is easy to use and does what it should, great!, However, I added some -desc
sister sorts for reverse sorting.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">xah-dired-sort</span> ()
<span style="color: #cd6600;">"Sort dired dir listing in different ways.</span>
<span style="color: #cd6600;">Prompt for a choice.</span>
<span style="color: #cd6600;">URL `</span><span style="color: #cd6600;">http://ergoemacs.org/emacs/dired_sort.html</span><span style="color: #cd6600;">'</span>
<span style="color: #cd6600;">Version 2015-07-30"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> (sort-by arg)
(<span style="color: #0000ff;">setq</span> sort-by (ido-completing-read <span style="color: #ff0000;">"Sort by:"</span> '( <span style="color: #ff0000;">"date"</span> <span style="color: #ff0000;">"size"</span> <span style="color: #ff0000;">"name"</span> <span style="color: #ff0000;">"dir"</span> <span style="color: #ff0000;">"date-desc"</span> <span style="color: #ff0000;">"size-desc"</span> <span style="color: #ff0000;">"name-desc"</span> <span style="color: #ff0000;">"dir-desc"</span> )))
(<span style="color: #0000ff;">cond</span>
((equal sort-by <span style="color: #ff0000;">"name"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso "</span>))
((equal sort-by <span style="color: #ff0000;">"date"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso -t"</span>))
((equal sort-by <span style="color: #ff0000;">"size"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso -S"</span>))
((equal sort-by <span style="color: #ff0000;">"dir"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso --group-directories-first"</span>))
((equal sort-by <span style="color: #ff0000;">"name-desc"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso -r"</span>))
((equal sort-by <span style="color: #ff0000;">"date-desc"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso -t -r"</span>))
((equal sort-by <span style="color: #ff0000;">"size-desc"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso -S -r"</span>))
((equal sort-by <span style="color: #ff0000;">"dir-desc"</span>) (<span style="color: #0000ff;">setq</span> arg <span style="color: #ff0000;">"-Al --si --time-style long-iso --group-directories-first -r"</span>))
(t (<span style="color: #ff0000; font-weight: bold;">error</span> <span style="color: #ff0000;">"logic error 09535"</span> )))
(dired-sort-other arg )))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="org6d9897e"></a>dired git helpers<br /><div class="outline-text-5" id="text-6-4-28-4">
2020-09-02 20:44:21 +02:00
<p>
<a href="http://blog.binchen.org/posts/the-most-efficient-way-to-git-add-file-in-dired-mode-emacsendiredgit.html">via bin chen</a>:
make git commands available from dired buffer, which can be used in
those rare cases, where my wrappers below don't fit.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">diredext-exec-git-command-in-shell</span> (command <span style="color: #483d8b;">&amp;optional</span> arg file-list)
<span style="color: #cd6600;">"Run a shell command git COMMAND ' on the marked files. if no</span>
<span style="color: #cd6600;">files marked, always operate on current line in dired-mode"</span>
(<span style="color: #0000ff;">interactive</span>
(<span style="color: #0000ff;">let</span> ((files (dired-get-marked-files t current-prefix-arg)))
(list
<span style="color: #006400;">;; </span><span style="color: #006400;">Want to give feedback whether this file or marked files are used:</span>
(dired-read-shell-command <span style="color: #ff0000;">"git command on %s: "</span> current-prefix-arg files)
current-prefix-arg
files)))
(<span style="color: #0000ff;">unless</span> (string-match <span style="color: #ff0000;">"[?][ \t]\'"</span> command)
(<span style="color: #0000ff;">setq</span> command (concat command <span style="color: #ff0000;">" *"</span>)))
(<span style="color: #0000ff;">setq</span> command (concat <span style="color: #ff0000;">"git "</span> command))
(dired-do-shell-command command arg file-list)
(message command))
</pre>
</div>
<p>
some git commandline wrappers which directly work on git files,
called with "hydras".
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dired-git-add</span>(<span style="color: #483d8b;">&amp;optional</span> arg file-list)
<span style="color: #cd6600;">"Add marked or current file to current repository (stash)."</span>
(<span style="color: #0000ff;">interactive</span>
(<span style="color: #0000ff;">let</span> ((files (dired-get-marked-files t current-prefix-arg)))
(list current-prefix-arg files)))
(dired-do-shell-command <span style="color: #ff0000;">"git add -v * "</span> arg file-list)
(revert-buffer))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dired-git-rm</span>(<span style="color: #483d8b;">&amp;optional</span> arg file-list)
<span style="color: #cd6600;">"Remove marked or current file from current repository and filesystem."</span>
(<span style="color: #0000ff;">interactive</span>
(<span style="color: #0000ff;">let</span> ((files (dired-get-marked-files t current-prefix-arg)))
(list current-prefix-arg files)))
(dired-do-shell-command <span style="color: #ff0000;">"git rm -rf * "</span> arg file-list)
(revert-buffer))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dired-git-ungit</span>(<span style="color: #483d8b;">&amp;optional</span> arg file-list)
<span style="color: #cd6600;">"Like `</span><span style="color: #cd6600;">tvd-dired-git-rm</span><span style="color: #cd6600;">' but keep the files in the filesystem (unstage)."</span>
(<span style="color: #0000ff;">interactive</span>
(<span style="color: #0000ff;">let</span> ((files (dired-get-marked-files t current-prefix-arg)))
(list current-prefix-arg files)))
(dired-do-shell-command <span style="color: #ff0000;">"git rm -rf --cached * "</span> arg file-list)
(revert-buffer))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="org7a922d4"></a>dired navigation<br /><div class="outline-text-5" id="text-6-4-28-5">
2020-09-02 20:44:21 +02:00
<p>
I'm used to jump around with pos1+end
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dired-begin</span> ()
<span style="color: #cd6600;">"Move point to the first directory in the listing .."</span>
(<span style="color: #0000ff;">interactive</span>)
(goto-char (point-min))
(dired-next-dirline 2))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dired-end</span> ()
<span style="color: #cd6600;">"Move point to the last file or directory in the listing."</span>
(<span style="color: #0000ff;">interactive</span>)
(goto-char (point-max))
(dired-previous-line 1))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="orgb068f6a"></a>dired buffer names<br /><div class="outline-text-5" id="text-6-4-28-6">
2020-09-02 20:44:21 +02:00
<p>
This took me a long time to figure out, but I finally got it: I
really hate it how dired names its buffers, it just uses the
basename part of the current working directory as buffer name. So
when there are a couple of dozen buffers open and one of them is
named "tmp" I just can't see it. So what I do here is to rename
each dired buffer right after its creation by advising
`dired-internal-noselect'. My dired buffers have such names now:
<b>dired: ~/tmp</b>. I can find them easily, and I can reach all dired
buffers very fast thanks to the *dired prefix. And they are now
clearly marked as non-file buffers. In fact I consider this
behavior as a bug, but I doubt many people would agree :)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(advice-add <span style="color: #ff00ff;">'dired-internal-noselect</span>
<span style="color: #8a2be2;">:filter-return</span>
'(<span style="color: #0000ff;">lambda</span> (buffer)
<span style="color: #cd6600;">"Modify dired buffer names to this pattern: *dired: full-path*"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">with-current-buffer</span> buffer
(rename-buffer (format <span style="color: #ff0000;">"*dired: %s*"</span> default-directory)))
buffer))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="orgb040f2b"></a>dired config and key bindings<br /><div class="outline-text-5" id="text-6-4-28-7">
2020-09-02 20:44:21 +02:00
<p>
and finally put everything together.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff00ff;">'dired</span>
'(<span style="color: #0000ff;">progn</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">dired vars</span>
(<span style="color: #0000ff;">setq</span> dired-listing-switches <span style="color: #ff0000;">"-lt"</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">stay with 1 dired buffer per instance</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">when changing directories</span>
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"RET"</span>) <span style="color: #ff00ff;">'dired-find-alternate-file</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-right&gt;"</span>) <span style="color: #ff00ff;">'dired-find-alternate-file</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"^"</span>) (<span style="color: #0000ff;">lambda</span> () (<span style="color: #0000ff;">interactive</span>) (find-alternate-file <span style="color: #ff0000;">".."</span>)))
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-left&gt;"</span>) (<span style="color: #0000ff;">lambda</span> () (<span style="color: #0000ff;">interactive</span>) (find-alternate-file <span style="color: #ff0000;">".."</span>)))
<span style="color: #006400;">;; </span><span style="color: #006400;">Xah Lee'S custom sort's</span>
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"s"</span>) <span style="color: #ff00ff;">'xah-dired-sort</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">my git "hydras"</span>
(define-prefix-command <span style="color: #ff00ff;">'tvd-dired-git-map</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"g"</span>) <span style="color: #ff00ff;">'tvd-dired-git-map</span>)
(define-key tvd-dired-git-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"a"</span>) <span style="color: #ff00ff;">'tvd-dired-git-add</span>)
(define-key tvd-dired-git-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"d"</span>) <span style="color: #ff00ff;">'tvd-dired-git-rm</span>)
(define-key tvd-dired-git-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"u"</span>) <span style="color: #ff00ff;">'tvd-dired-git-ungit</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">edit filenames</span>
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'edit-dired</span> <span style="color: #ff00ff;">'wdired-change-to-wdired-mode</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-c C-c"</span>) <span style="color: #ff00ff;">'wdired-change-to-wdired-mode</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">dired-hacks filters</span>
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"f"</span>) dired-filter-map)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"q"</span>) <span style="color: #ff00ff;">'tvd-dired-quit-or-filter-pop</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"Q"</span>) <span style="color: #ff00ff;">'dired-filter-pop-all</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">ranger, multi file copy/move</span>
(define-prefix-command <span style="color: #ff00ff;">'tvd-dired-ranger-map</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"r"</span>) <span style="color: #ff00ff;">'tvd-dired-ranger-map</span>)
(define-key tvd-dired-ranger-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"c"</span>) <span style="color: #ff00ff;">'dired-ranger-copy</span>)
(define-key tvd-dired-ranger-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"p"</span>) <span style="color: #ff00ff;">'dired-ranger-paste</span>)
(define-key tvd-dired-ranger-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"m"</span>) <span style="color: #ff00ff;">'dired-ranger-move</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">navigation, use TAB and C-TAB to move</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">point to next or prev dir like in info</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">mode, and HOME+END to reach the end or</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">beginning of the listing.</span>
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;tab&gt;"</span>) <span style="color: #ff00ff;">'dired-next-dirline</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;C-tab&gt;"</span>) <span style="color: #ff00ff;">'dired-prev-dirline</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;home&gt;"</span>) <span style="color: #ff00ff;">'tvd-dired-begin</span>)
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;end&gt;"</span>) <span style="color: #ff00ff;">'tvd-dired-end</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">overwrite some defaults I do not use anyway</span>
(define-key dired-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"n"</span>) <span style="color: #ff00ff;">'dired-create-directory</span>)))
</pre>
</div>
</div></li>
2021-05-01 13:15:16 +02:00
<li><a id="orgf9fc09b"></a>Dired Hydra<br /><div class="outline-text-5" id="text-6-4-28-8">
2020-09-02 20:44:21 +02:00
<p>
<i>FIXME</i>: not yet customized to fit my own config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defhydra</span> hydra-dired (<span style="color: #8a2be2;">:hint</span> nil <span style="color: #8a2be2;">:color</span> pink)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">_+_ mkdir _v_iew _m_ark _(_ details _i_nsert-subdir _W_dired (EDIT FILENAMES)</span>
<span style="color: #cd6600;">_C_opy _O_ view other _U_nmark all _)_ omit-mode _$_ hide-subdir C-c C-c : edit</span>
<span style="color: #cd6600;">_D_elete _o_pen other _u_nmark _l_ redisplay _w_ kill-subdir</span>
<span style="color: #cd6600;">_R_ename _M_ chmod _t_oggle _g_ revert buf _e_ ediff _q_uit</span>
<span style="color: #cd6600;">_Y_ rel symlink _G_ chgrp _E_xtension mark _s_ort _=_ pdiff</span>
<span style="color: #cd6600;">_S_ymlink ^ ^ _F_ind marked _._ toggle hydra \\ flyspell</span>
<span style="color: #cd6600;">_r_sync ^ ^ ^ ^ ^ ^ _?_ summary</span>
<span style="color: #cd6600;">_z_ compress-file _A_ find regexp / Filter</span>
<span style="color: #cd6600;">_Z_ compress _Q_ repl regexp</span>
<span style="color: #cd6600;">T - tag prefix</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"\\"</span> dired-do-ispell nil)
(<span style="color: #ff0000;">"("</span> dired-hide-details-mode nil)
(<span style="color: #ff0000;">")"</span> dired-omit-mode nil)
(<span style="color: #ff0000;">"+"</span> dired-create-directory nil)
(<span style="color: #ff0000;">"="</span> diredp-ediff nil) <span style="color: #006400;">;; </span><span style="color: #006400;">smart diff</span>
(<span style="color: #ff0000;">"?"</span> dired-summary nil)
(<span style="color: #ff0000;">"$"</span> diredp-hide-subdir-nomove nil)
(<span style="color: #ff0000;">"A"</span> dired-do-find-regexp nil)
(<span style="color: #ff0000;">"C"</span> dired-do-copy nil) <span style="color: #006400;">;; </span><span style="color: #006400;">Copy all marked files</span>
(<span style="color: #ff0000;">"D"</span> dired-do-delete nil)
(<span style="color: #ff0000;">"E"</span> dired-mark-extension nil)
(<span style="color: #ff0000;">"e"</span> dired-ediff-files nil)
(<span style="color: #ff0000;">"F"</span> dired-do-find-marked-files nil)
(<span style="color: #ff0000;">"G"</span> dired-do-chgrp nil)
(<span style="color: #ff0000;">"g"</span> revert-buffer nil) <span style="color: #006400;">;; </span><span style="color: #006400;">read all directories again (refresh nil)</span>
(<span style="color: #ff0000;">"i"</span> dired-maybe-insert-subdir nil)
(<span style="color: #ff0000;">"l"</span> dired-do-redisplay nil) <span style="color: #006400;">;; </span><span style="color: #006400;">relist the marked or singel directory</span>
(<span style="color: #ff0000;">"M"</span> dired-do-chmod nil)
(<span style="color: #ff0000;">"m"</span> dired-mark nil)
(<span style="color: #ff0000;">"O"</span> dired-display-file nil)
(<span style="color: #ff0000;">"o"</span> dired-find-file-other-window nil)
(<span style="color: #ff0000;">"Q"</span> dired-do-find-regexp-and-replace nil)
(<span style="color: #ff0000;">"R"</span> dired-do-rename nil)
(<span style="color: #ff0000;">"r"</span> dired-do-rsynch nil)
(<span style="color: #ff0000;">"S"</span> dired-do-symlink nil)
(<span style="color: #ff0000;">"s"</span> dired-sort-toggle-or-edit nil)
(<span style="color: #ff0000;">"t"</span> dired-toggle-marks nil)
(<span style="color: #ff0000;">"U"</span> dired-unmark-all-marks nil)
(<span style="color: #ff0000;">"u"</span> dired-unmark nil)
(<span style="color: #ff0000;">"v"</span> dired-view-file nil) <span style="color: #006400;">;; </span><span style="color: #006400;">q to exit, s to search, = gets line #</span>
(<span style="color: #ff0000;">"w"</span> dired-kill-subdir nil)
(<span style="color: #ff0000;">"W"</span> wdired-change-to-wdired-mode nil)
(<span style="color: #ff0000;">"Y"</span> dired-do-relsymlink nil)
(<span style="color: #ff0000;">"z"</span> diredp-compress-this-file nil)
(<span style="color: #ff0000;">"Z"</span> dired-do-compress nil)
(<span style="color: #ff0000;">"q"</span> nil nil)
(<span style="color: #ff0000;">"."</span> nil nil <span style="color: #8a2be2;">:color</span> blue))
(define-key dired-mode-map <span style="color: #ff0000;">"?"</span> <span style="color: #ff00ff;">'hydra-dired</span>/body)
</pre>
</div>
</div></li></ol>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org29a5953" class="outline-4">
<h4 id="org29a5953"><span class="section-number-4">6.4.29</span> Ediff Config</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-29">
2020-09-02 20:44:21 +02:00
<p>
Force ediff to use 1 frame (the current) and not open a new frame
for control and help. Also changing the split orientation doesnt
open a new frame.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eval-after-load <span style="color: #ff0000;">"ediff"</span>
'(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">setq</span> ediff-diff-options <span style="color: #ff0000;">"-w"</span>
ediff-split-window-function <span style="color: #ff00ff;">'split-window-horizontally</span>
ediff-window-setup-function <span style="color: #ff00ff;">'ediff-setup-windows-plain</span>)
(add-hook <span style="color: #ff00ff;">'ediff-startup-hook</span> <span style="color: #ff00ff;">'ediff-toggle-wide-display</span>)
(add-hook <span style="color: #ff00ff;">'ediff-cleanup-hook</span> <span style="color: #ff00ff;">'ediff-toggle-wide-display</span>)
(add-hook <span style="color: #ff00ff;">'ediff-suspend-hook</span> <span style="color: #ff00ff;">'ediff-toggle-wide-display</span>)
(add-hook <span style="color: #ff00ff;">'ediff-mode-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
(ediff-setup-keymap)
<span style="color: #006400;">;; </span><span style="color: #006400;">merge left to right</span>
(define-key ediff-mode-map <span style="color: #ff0000;">"&gt;"</span> <span style="color: #ff00ff;">'ediff-copy-A-to-B</span>)
<span style="color: #006400;">;; </span><span style="color: #006400;">merge right to left</span>
(define-key ediff-mode-map <span style="color: #ff0000;">"&lt;"</span> <span style="color: #ff00ff;">'ediff-copy-B-to-A</span>)))
<span style="color: #006400;">;; </span><span style="color: #006400;">restore window config on quit</span>
(add-hook <span style="color: #ff00ff;">'ediff-after-quit-hook-internal</span> <span style="color: #ff00ff;">'winner-undo</span>)
))
</pre>
</div>
<p>
from emacswiki:
Usage: emacs -diff file1 file2
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">command-line-diff</span> (switch)
(<span style="color: #0000ff;">let</span> ((file1 (<span style="color: #0000ff;">pop</span> command-line-args-left))
(file2 (<span style="color: #0000ff;">pop</span> command-line-args-left)))
(ediff file1 file2)))
(add-to-list <span style="color: #ff00ff;">'command-switch-alist</span> '(<span style="color: #ff0000;">"diff"</span> . command-line-diff))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org6dc9a1f" class="outline-4">
<h4 id="org6dc9a1f"><span class="section-number-4">6.4.30</span> Smerge Config</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-30">
2020-09-02 20:44:21 +02:00
<p>
smerge-mode is being issued during editing of conflicts from magit,
however, I hate its default prefix, but don't have any practical
prefixes left AND am using it far too rare to deserve its own
prefix. So just a hydra will do.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defhydra</span> hydra-smerge (<span style="color: #8a2be2;">:color</span> blue <span style="color: #8a2be2;">:timeout</span> 30.0)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">^Smerge Mode^</span>
<span style="color: #cd6600;">^^-------------------------------------------------------</span>
<span style="color: #cd6600;">_n_ext conflict keep _u_pper m_e_rge conflicts in Ediff</span>
<span style="color: #cd6600;">_p_revious conflict keep _l_ower _q_uit"</span>
(<span style="color: #ff0000;">"n"</span> smerge-next nil <span style="color: #8a2be2;">:exit</span> nil)
(<span style="color: #ff0000;">"p"</span> smerge-prev nil <span style="color: #8a2be2;">:exit</span> nil)
(<span style="color: #ff0000;">"u"</span> smerge-keep-upper nil <span style="color: #8a2be2;">:exit</span> nil)
(<span style="color: #ff0000;">"l"</span> smerge-keep-lower nil <span style="color: #8a2be2;">:exit</span> nil)
(<span style="color: #ff0000;">"e"</span> smerge-ediff nil <span style="color: #8a2be2;">:color</span> red)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'merge</span> <span style="color: #ff00ff;">'hydra-smerge</span>/body)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgcc90b8a" class="outline-4">
<h4 id="orgcc90b8a"><span class="section-number-4">6.4.31</span> Projectile</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-31">
2020-09-02 20:44:21 +02:00
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'projectile</span>)
(projectile-mode +1)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-dir-to-projectile</span> ()
<span style="color: #cd6600;">"drop a .projectile wherever we are"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">with-temp-file</span> <span style="color: #ff0000;">".projectile"</span>
(insert <span style="color: #ff0000;">"-.snapshot\n-.git\n-.RCS\n"</span>))
(message (format <span style="color: #ff0000;">"Turned %s into projectile project"</span> default-directory)))
</pre>
</div>
<p>
<i>FIXME</i>: add custom docstring
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defhydra</span> hydra-projectile
( <span style="color: #8a2be2;">:color</span> teal
<span style="color: #8a2be2;">:columns</span> 4)
<span style="color: #cd6600;">"Projectile (use C-p for this menu)"</span>
(<span style="color: #ff0000;">"s"</span> projectile-switch-project <span style="color: #ff0000;">"Switch Project"</span>)
(<span style="color: #ff0000;">"f"</span> projectile-find-file <span style="color: #ff0000;">"Find File"</span>)
(<span style="color: #ff0000;">"r"</span> projectile-recentf <span style="color: #ff0000;">"Recent Files"</span>)
(<span style="color: #ff0000;">"b"</span> projectile-ibuffer <span style="color: #ff0000;">"Show Project Buffers"</span>)
(<span style="color: #ff0000;">"g"</span> projectile-grep <span style="color: #ff0000;">"Grep"</span>)
(<span style="color: #ff0000;">"o"</span> projectile-multi-occur <span style="color: #ff0000;">"Multi Occur"</span>)
(<span style="color: #ff0000;">"d"</span> projectile-dired <span style="color: #ff0000;">"Project Dired"</span>)
(<span style="color: #ff0000;">"R"</span> projectile-replace <span style="color: #ff0000;">"Replace in Project"</span>)
(<span style="color: #ff0000;">"C"</span> projectile-invalidate-cache <span style="color: #ff0000;">"Clear Cache"</span>)
(<span style="color: #ff0000;">"t"</span> projectile-regenerate-tags <span style="color: #ff0000;">"Regenerate Tags"</span>)
(<span style="color: #ff0000;">"X"</span> projectile-cleanup-known-projects <span style="color: #ff0000;">"Cleanup Known Projects"</span>)
(<span style="color: #ff0000;">"n"</span> tvd-dir-to-projectile <span style="color: #ff0000;">"Turn current directory into Projectile"</span>)
(<span style="color: #ff0000;">"c"</span> projectile-commander <span style="color: #ff0000;">"Commander"</span>)
(<span style="color: #ff0000;">"k"</span> projectile-kill-buffers <span style="color: #ff0000;">"Kill Buffers"</span>)
(<span style="color: #ff0000;">"q"</span> nil <span style="color: #ff0000;">"Cancel"</span> <span style="color: #8a2be2;">:color</span> blue))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x p"</span>) <span style="color: #ff00ff;">'hydra-projectile</span>/body)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org41fb6c7" class="outline-4">
<h4 id="org41fb6c7"><span class="section-number-4">6.4.32</span> Occur</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-32">
2020-09-02 20:44:21 +02:00
<p>
<a href="https://oremacs.com/2015/01/26/occur-dwim/">https://oremacs.com/2015/01/26/occur-dwim/</a>
<a href="https://github.com/abo-abo/hydra/wiki/Emacs">https://github.com/abo-abo/hydra/wiki/Emacs</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">occur-dwim</span> ()
<span style="color: #cd6600;">"Call `</span><span style="color: #cd6600;">occur</span><span style="color: #cd6600;">' with a sane default, chosen as the thing under point or selected region"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">push</span> (<span style="color: #0000ff;">if</span> (region-active-p)
(buffer-substring-no-properties
(region-beginning)
(region-end))
(<span style="color: #0000ff;">let</span> ((sym (thing-at-point <span style="color: #ff00ff;">'symbol</span>)))
(<span style="color: #0000ff;">when</span> (stringp sym)
(regexp-quote sym))))
regexp-history)
(call-interactively <span style="color: #ff00ff;">'occur</span>))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org977f4e2" class="outline-4">
<h4 id="org977f4e2"><span class="section-number-4">6.4.33</span> Window Hydra</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-33">
2020-09-02 20:44:21 +02:00
<p>
brightness wrappers
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-bg-brighter</span> ()
(<span style="color: #0000ff;">interactive</span>)
(doremi-increment-background-color-1 ?v -1))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-bg-darker</span> ()
(<span style="color: #0000ff;">interactive</span>)
(doremi-increment-background-color-1 ?v 1))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-pre-resize</span> ()
<span style="color: #cd6600;">"Called as pre execute hook py hydra-windows-resize/body and</span>
<span style="color: #cd6600;">executes the called key once, so that no key press gets lost from</span>
<span style="color: #cd6600;">hydra-windows (a,s,d,w)"</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span>
((key (<span style="color: #0000ff;">car</span> (reverse (append (recent-keys) nil)))))
(<span style="color: #0000ff;">cond</span>
((<span style="color: #0000ff;">eq</span> key ?a)
(shrink-window-horizontally 1))
((<span style="color: #0000ff;">eq</span> key ?d)
(enlarge-window-horizontally 1))
((<span style="color: #0000ff;">eq</span> key ?w)
(shrink-window 1))
((<span style="color: #0000ff;">eq</span> key ?s)
(enlarge-window 1)))))
(<span style="color: #0000ff;">defhydra</span> hydra-windows-resize (<span style="color: #8a2be2;">:color</span> pink <span style="color: #8a2be2;">:pre</span> (tvd-pre-resize))
<span style="color: #006400;">;; </span><span style="color: #006400;">small sub hydra for window resizing, it leaves as much room for</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">windows as possible</span>
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">_a_ || _d_ |---| _w_ --- _s_ ="</span>
(<span style="color: #ff0000;">"a"</span> shrink-window-horizontally nil)
(<span style="color: #ff0000;">"d"</span> enlarge-window-horizontally nil)
(<span style="color: #ff0000;">"w"</span> shrink-window nil)
(<span style="color: #ff0000;">"s"</span> enlarge-window nil)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
(<span style="color: #0000ff;">defhydra</span> hydra-windows (<span style="color: #8a2be2;">:color</span> blue)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">^Window Management^</span>
<span style="color: #cd6600;">^^------------------------------------------------------------------------</span>
<span style="color: #cd6600;">_+_ Increase Font | _-_ Decrease Font Resize ^ ^ _w_ ^ ^</span>
<span style="color: #cd6600;">_f_: Flip Windows &lt;M-O&gt; ^^ Current _a_ ^ ^ _d_</span>
<span style="color: #cd6600;">_4_: Quarter Windows &lt;C-x 4&gt; ^^ Window: ^ ^ _s_ ^ ^</span>
<span style="color: #cd6600;">_u_: Windows Undo &lt;C-c left&gt;</span>
<span style="color: #cd6600;">_r_: Windows Redo &lt;C-c right&gt; ^^ _l_: Adjust Background brighter</span>
<span style="color: #cd6600;">_i_: Invert Colors &lt;C-c C-i&gt; ^^ _b_: Adjust Background darker</span>
<span style="color: #cd6600;">_h_: Toggle Highlight Line Mode ^^ _e_: Eyebrowse Workspaces (C-x C-x)</span>
<span style="color: #cd6600;">_n_: Toogle Line Number Mode</span>
<span style="color: #cd6600;">^^------------------------------------------------------------------------</span>
<span style="color: #cd6600;">Reach this hydra with &lt;C-x w&gt;</span>
<span style="color: #cd6600;">^^------------------------------------------------------------------------</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"+"</span> tvd-global-font-size-bigger nil <span style="color: #8a2be2;">:color</span> pink)
(<span style="color: #ff0000;">"-"</span> tvd-global-font-size-smaller nil <span style="color: #8a2be2;">:color</span> pink)
(<span style="color: #ff0000;">"f"</span> tvd-flip-windows nil)
(<span style="color: #ff0000;">"4"</span> tvd-quarter-windows nil)
(<span style="color: #ff0000;">"u"</span> winner-undo nil)
(<span style="color: #ff0000;">"r"</span> winner-redo nil)
(<span style="color: #ff0000;">"i"</span> tvd-invert nil)
(<span style="color: #ff0000;">"b"</span> tvd-bg-darker nil <span style="color: #8a2be2;">:color</span> pink)
(<span style="color: #ff0000;">"l"</span> tvd-bg-brighter nil <span style="color: #8a2be2;">:color</span> pink)
(<span style="color: #ff0000;">"a"</span> hydra-windows-resize/body nil)
(<span style="color: #ff0000;">"d"</span> hydra-windows-resize/body nil)
(<span style="color: #ff0000;">"w"</span> hydra-windows-resize/body nil)
(<span style="color: #ff0000;">"s"</span> hydra-windows-resize/body nil)
(<span style="color: #ff0000;">"e"</span> hydra-eyebrowse/body nil)
(<span style="color: #ff0000;">"h"</span> hl-line-mode nil)
(<span style="color: #ff0000;">"n"</span> linum-mode nil)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x w"</span>) <span style="color: #ff00ff;">'hydra-windows</span>/body)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgcb8f76f" class="outline-4">
<h4 id="orgcb8f76f"><span class="section-number-4">6.4.34</span> Eyebrowse Workspaces</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-34">
2020-09-02 20:44:21 +02:00
<p>
workspace configuration, like desktops. Seems to be a good implementation, w/o save though
</p>
<p>
"prefix key" has to be set before loading, keep in mind, that
if you change it here, you need to change it below as well!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> eyebrowse-keymap-prefix (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x"</span>))
(global-unset-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x"</span>))
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'eyebrowse</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-new-eyebrowse-workspace</span> ()
<span style="color: #cd6600;">"Create new scratch buffer and ask for a name"</span>
(<span style="color: #0000ff;">interactive</span>)
(eyebrowse-rename-window-config (eyebrowse--get <span style="color: #ff00ff;">'current-slot</span>) (read-string <span style="color: #ff0000;">"Workspace: "</span>))
(autoscratch-buffer))
</pre>
</div>
<p>
always enable
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(eyebrowse-mode t)
(<span style="color: #0000ff;">setq</span> eyebrowse-new-workspace <span style="color: #ff00ff;">'tvd-new-eyebrowse-workspace</span>
eyebrowse-switch-back-and-forth t
eyebrowse-wrap-around t
eyebrowse-mode-line-style t
eyebrowse-slot-format <span style="color: #ff0000;">"%s:init"</span>)
</pre>
</div>
<p>
add a hydra, just in case, it contains hydra commands and hints
about the actual key bindings, it's also being refered from
hydra-window/body with "e"
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defhydra</span> hydra-eyebrowse (<span style="color: #8a2be2;">:color</span> blue)
<span style="color: #cd6600;">"</span>
<span style="color: #cd6600;">^Eyebrowse Workspace Management^</span>
<span style="color: #cd6600;">^^--------------------------------------</span>
<span style="color: #cd6600;">_l_: last window (C-x C-x C-x)</span>
<span style="color: #cd6600;">_n_: next window (C-x C-x &lt;right&gt;)</span>
<span style="color: #cd6600;">_p_: prev window (C-x C-x &lt;left&gt;)</span>
<span style="color: #cd6600;">_x_: close workspace (C-x C-x q)</span>
<span style="color: #cd6600;">_t_: rename workspace (C-x C-x t)</span>
<span style="color: #cd6600;">_c_: create workspace (C-x C-x n)</span>
<span style="color: #cd6600;">Use C-x C-x to access eyebrowse directly.</span>
<span style="color: #cd6600;">"</span>
(<span style="color: #ff0000;">"l"</span> eyebrowse-last-window-config nil)
(<span style="color: #ff0000;">"n"</span> eyebrowse-next-window-config nil)
(<span style="color: #ff0000;">"p"</span> eyebrowse-prev-window-config nil)
(<span style="color: #ff0000;">"x"</span> eyebrowse-close-window-config nil)
(<span style="color: #ff0000;">"t"</span> eyebrowse-rename-window-config nil)
(<span style="color: #ff0000;">"c"</span> eyebrowse-create-window-config nil)
(<span style="color: #ff0000;">"q"</span> nil nil <span style="color: #8a2be2;">:color</span> red))
</pre>
</div>
<p>
Modifying the eyebrowse keymap directly doesn't work because it's
not setup correctly. I sent a pull request to fix this:
<a href="https://github.com/wasamasa/eyebrowse/pull/94">https://github.com/wasamasa/eyebrowse/pull/94</a>, however, vaslilly choosed
not to accept it. So, I need to configure the whole chords for every
function I use AND set the "prefix key" using the weird way above
(before loading).
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x C-x"</span>) <span style="color: #ff00ff;">'eyebrowse-last-window-config</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x &lt;right&gt;"</span>) <span style="color: #ff00ff;">'eyebrowse-next-window-config</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x &lt;left&gt;"</span>) <span style="color: #ff00ff;">'eyebrowse-prev-window-config</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x q"</span>) <span style="color: #ff00ff;">'eyebrowse-close-window-config</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x t"</span>) <span style="color: #ff00ff;">'eyebrowse-rename-window-config</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x n"</span>) <span style="color: #ff00ff;">'eyebrowse-create-window-config</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-x ?"</span>) <span style="color: #ff00ff;">'hydra-eyebrowse</span>/body)
</pre>
</div>
<p>
There's also some face config, see defcustom at end of file!
</p>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgf0465a8" class="outline-4">
<h4 id="orgf0465a8"><span class="section-number-4">6.4.35</span> Highlighting Indentation</h4>
2020-11-26 20:56:59 +01:00
<div class="outline-text-4" id="text-6-4-35">
2020-09-02 20:44:21 +02:00
<p>
provides: highlight-indentation-mode and highlight-indentation-current-column-mode
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'highlight-indentation</span>)
(add-something-to-mode-hooks
'(yaml python ruby) <span style="color: #ff00ff;">'highlight-indentation-current-column-mode</span>)
(set-face-background <span style="color: #ff00ff;">'highlight-indentation-face</span> <span style="color: #ff0000;">"#e3e3d3"</span>)
(set-face-background <span style="color: #ff00ff;">'highlight-indentation-current-column-face</span> <span style="color: #ff0000;">"#c3b3b3"</span>)
</pre>
</div>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org0dd293d" class="outline-3">
<h3 id="org0dd293d"><span class="section-number-3">6.5</span> Emacs Interface</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-6-5">
2021-05-01 13:15:16 +02:00
</div><div id="outline-container-org5b2ea16" class="outline-4">
<h4 id="org5b2ea16"><span class="section-number-4">6.5.1</span> Parens</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-1">
<p>
display matching braces
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(show-paren-mode 1)
</pre>
</div>
<p>
'mixed: highlight all if the other paren is invisible
'expression: highlight the whole sexp
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> show-paren-style <span style="color: #ff00ff;">'mixed</span>)
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgf012fe3" class="outline-4">
<h4 id="orgf012fe3"><span class="section-number-4">6.5.2</span> highlight todo keywords (such as <i>FIXME</i>)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-2">
<p>
Absolutely needed!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'fic-mode</span>)
(add-something-to-mode-hooks '(c c++ cperl vala web emacs-lisp ruby python) <span style="color: #ff00ff;">'turn-on-fic-mode</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org0b7cdde" class="outline-4">
<h4 id="org0b7cdde"><span class="section-number-4">6.5.3</span> UNDO Tree Mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-3">
<p>
Better undo, with redo support.
</p>
<p>
C-_ (`undo-tree-undo')
Undo changes.
</p>
<p>
C-: (`undo-tree-redo')
Redo changes.
</p>
<p>
more: see undo-tree.el
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'undo-tree</span>)
</pre>
</div>
<p>
use always
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-undo-tree-mode)
</pre>
</div>
<p>
M-_ catched by Xmonad
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-:"</span>) <span style="color: #ff00ff;">'undo-tree-redo</span>) <span style="color: #006400;">; </span><span style="color: #006400;">C-: == REDO C-_ == UNDO</span>
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgfebbe55" class="outline-4">
<h4 id="orgfebbe55"><span class="section-number-4">6.5.4</span> Smarter M-x Mode (smex)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-4">
<p>
This is really cool and I don't know how I could ever live without it.
</p>
<p>
fails @win, so wrap it
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">safe-wrap</span>
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'smex</span>)
(smex-initialize)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-x"</span>) <span style="color: #ff00ff;">'smex</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-X"</span>) <span style="color: #ff00ff;">'smex-major-mode-commands</span>))
(message <span style="color: #ff0000;">"ignoring unsupported smex"</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org593e3c6" class="outline-4">
<h4 id="org593e3c6"><span class="section-number-4">6.5.5</span> Smarter Search</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-5">
<p>
test, replace isearch-forward-regexp first only.
dir: ivy/
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'swiper</span>)
(<span style="color: #0000ff;">with-eval-after-load</span> <span style="color: #ff00ff;">'swiper</span>
(<span style="color: #0000ff;">setq</span> ivy-wrap t)
(global-set-key <span style="color: #ff0000;">"\C-s"</span> <span style="color: #ff00ff;">'swiper</span>))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org43ae527" class="outline-4">
<h4 id="org43ae527"><span class="section-number-4">6.5.6</span> Which Func</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-6">
<p>
display current function - if any - in mode line
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-something-to-mode-hooks
'(c c++ cperl vala makefile ruby shell-script python)
<span style="color: #ff00ff;">'which-func-mode</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org46c1a5e" class="outline-4">
<h4 id="org46c1a5e"><span class="section-number-4">6.5.7</span> Show current-line in the Fringe</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-7">
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'fringe-current-line</span>)
(global-fringe-current-line-mode 1)
</pre>
</div>
<p>
also change the color (matching the mode line
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(set-face-attribute <span style="color: #ff00ff;">'fringe</span> nil <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"NavyBlue"</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org3d68b6b" class="outline-4">
<h4 id="org3d68b6b"><span class="section-number-4">6.5.8</span> Recent Files</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-8">
<p>
You know the file you edited yesterday had "kri" in its name, but
where was it? You don't remember. But don't worry, recent files is
your friend. It shows the last N files you edited recently.
I use it permanently.
</p>
<p>
see also: ido-mode and smex
</p>
<p>
setup
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'recentf</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'cl-lib</span>)
(<span style="color: #0000ff;">setq</span> recentf-auto-cleanup <span style="color: #ff00ff;">'never</span>) <span style="color: #006400;">;; </span><span style="color: #006400;">avoid stat() on tramp buffers</span>
(recentf-mode 1)
</pre>
</div>
<p>
I like to have a longer list reaching deeper into the past
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> recentf-max-menu-items 200
recentf-max-saved-items nil)
</pre>
</div>
<p>
enable IDO completion
via <a href="http://emacsredux.com/blog/2013/04/05/recently-visited-files/">emacsredux</a>
modified to exclude already visited files
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-buffer-exists-p</span> (bufname)
(<span style="color: #0000ff;">not</span> (<span style="color: #0000ff;">eq</span> nil (get-file-buffer bufname))))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">recentf-ido-find-file</span> ()
<span style="color: #cd6600;">"Find a recent file using ido."</span>
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">let</span> ((file (ido-completing-read
<span style="color: #ff0000;">"Choose recent file: "</span>
(cl-remove-if <span style="color: #ff00ff;">'tvd-buffer-exists-p</span> recentf-list) nil t)))
(<span style="color: #0000ff;">when</span> file
(find-file file))))
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-r"</span>) <span style="color: #ff00ff;">'recentf-ido-find-file</span>) <span style="color: #006400;">; </span><span style="color: #006400;">open recent files, same as M-x rf</span>
</pre>
</div>
<p>
now if I incidentally closed a buffer, I can re-open it, thanks to
recent-files
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">undo-kill-buffer</span> (arg)
<span style="color: #cd6600;">"Re-open the last buffer killed. With ARG, re-open the nth buffer."</span>
(<span style="color: #0000ff;">interactive</span> <span style="color: #ff0000;">"p"</span>)
(<span style="color: #0000ff;">let</span> ((recently-killed-list (copy-sequence recentf-list))
(buffer-files-list
(delq nil (mapcar (<span style="color: #0000ff;">lambda</span> (buf)
(<span style="color: #0000ff;">when</span> (buffer-file-name buf)
(expand-file-name (buffer-file-name buf)))) <span style="color: #ff0000; font-weight: bold;">(buffer-list)))))</span>
(mapc
(<span style="color: #0000ff;">lambda</span> (buf-file)
(<span style="color: #0000ff;">setq</span> recently-killed-list
(delq buf-file recently-killed-list)))
buffer-files-list)
(find-file
(<span style="color: #0000ff;">if</span> arg (nth arg recently-killed-list)
(<span style="color: #0000ff;">car</span> recently-killed-list)))))
</pre>
</div>
<p>
exclude some auto generated files
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> recentf-exclude (list <span style="color: #ff0000;">"ido.last"</span>
<span style="color: #ff0000;">"/elpa/"</span>
<span style="color: #ff0000;">".el.gz$"</span>
'(<span style="color: #0000ff;">not</span> (file-readable-p))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org238949b" class="outline-4">
<h4 id="org238949b"><span class="section-number-4">6.5.9</span> IDO mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-9">
<p>
There are other completion enhancement packages available like ivy
for example, but I love IDO and I am so used to it, it would be
impossible to change. So, I'll stick with IDO until end of (my)
times.
</p>
<p>
Hint: Use C-f during file selection to switch to regular find-file
</p>
<p>
Basic config
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(ido-mode t)
(ido-everywhere nil)
(<span style="color: #0000ff;">setq</span> ido-enable-flex-matching t)
(<span style="color: #0000ff;">setq</span> ido-use-filename-at-point nil)
(<span style="color: #0000ff;">setq</span> ido-use-virtual-buffers t)
(<span style="color: #0000ff;">setq</span> ido-auto-merge-work-directories-length -1)
</pre>
</div>
<p>
One thing annoys me with IDO though: when writing a new file, IDO
wants me to select from a list of existing files. Since it is
nearly impossible to disable ido mode for write-file, which I HATE,
I came up with this:
</p>
<p>
I added a new global variable, 'tvd-ido-disabled, which is nil by
default. Whenever I hit C-x C-w (in order to execute write-file),
it will be set to t, ido mode will be disabled and ido-write-file
will be called. Since ido mode is now disabled, it just calls the
original write-file, which is what I really want.
</p>
<p>
When I'm finished selecting a filename and writing, ido mode will
be turned on again and the variable will be set to nil. However,
sometimes I may abort the process using C-g. In that case ido mode
may end up being disabled because the :after advice will not be
called on C-g.
</p>
<p>
So, I also advice the minibuffer C-g function, which is
'abort-recursive-edit, and re-enable ido mode from here if it is
still disabled. So far I haven't seen any bad side effects of this.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">tvd-ido-disabled</span> nil)
(advice-add <span style="color: #ff00ff;">'ido-write-file</span> <span style="color: #8a2be2;">:before</span> '(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args) (ido-mode 0) (<span style="color: #0000ff;">setq</span> tvd-ido-disabled t)))
(advice-add <span style="color: #ff00ff;">'ido-write-file</span> <span style="color: #8a2be2;">:after</span> '(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args) (ido-mode 1) (<span style="color: #0000ff;">setq</span> tvd-ido-disabled nil)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-keyboard-quit-advice</span> (fn <span style="color: #483d8b;">&amp;rest</span> args)
(<span style="color: #0000ff;">when</span> tvd-ido-disabled
(ido-mode 1)
(<span style="color: #0000ff;">setq</span> tvd-ido-disabled nil))
(apply fn args))
(advice-add <span style="color: #ff00ff;">'abort-recursive-edit</span> <span style="color: #8a2be2;">:around</span> #<span style="color: #ff00ff;">'tvd-keyboard-quit-advice</span>)
</pre>
</div>
<p>
from emacs wiki
Display ido results vertically, rather than horizontally
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> ido-decorations (<span style="color: #0000ff;">quote</span> (<span style="color: #ff0000;">"\n-&gt; "</span> <span style="color: #ff0000;">""</span> <span style="color: #ff0000;">"\n "</span> <span style="color: #ff0000;">"\n ..."</span> <span style="color: #ff0000;">"["</span> <span style="color: #ff0000;">"]"</span>
<span style="color: #ff0000;">" [No match]"</span> <span style="color: #ff0000;">" [Matched]"</span> <span style="color: #ff0000;">" [Not readable]"</span>
<span style="color: #ff0000;">" [Too big]"</span> <span style="color: #ff0000;">" [Confirm]"</span>)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">ido-disable-line-truncation</span> () (<span style="color: #0000ff;">set</span> (make-local-variable <span style="color: #ff00ff;">'truncate-lines</span>) nil))
(add-hook <span style="color: #ff00ff;">'ido-minibuffer-setup-hook</span> <span style="color: #ff00ff;">'ido-disable-line-truncation</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">ido-define-keys</span> ()
(define-key ido-completion-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;down&gt;"</span>) <span style="color: #ff00ff;">'ido-next-match</span>)
(define-key ido-completion-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"&lt;up&gt;"</span>) <span style="color: #ff00ff;">'ido-prev-match</span>))
(add-hook <span style="color: #ff00ff;">'ido-setup-hook</span> <span style="color: #ff00ff;">'ido-define-keys</span>)
</pre>
</div>
<p>
quickly go to home via ~ wherever I am
via <a href="http://whattheemacsd.com/setup-ido.el-02.html">whattheemacs.d</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'ido-setup-hook</span>
(<span style="color: #0000ff;">lambda</span> ()
<span style="color: #006400;">;; </span><span style="color: #006400;">Go straight home</span>
(define-key ido-file-completion-map
(<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"~"</span>)
(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (looking-back <span style="color: #ff0000;">"/"</span>)
(insert <span style="color: #ff0000;">"~/"</span>)
(call-interactively <span style="color: #ff00ff;">'self-insert-command</span>))))
<span style="color: #006400;">;; </span><span style="color: #006400;">same thing, but for ssh/tramp triggered by :</span>
(define-key ido-file-completion-map
(<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">":"</span>)
(<span style="color: #0000ff;">lambda</span> ()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">if</span> (looking-back <span style="color: #ff0000;">"/"</span>)
(<span style="color: #0000ff;">progn</span>
(ido-set-current-directory <span style="color: #ff0000;">"/ssh:"</span>)
(ido-reread-directory))
(call-interactively <span style="color: #ff00ff;">'self-insert-command</span>))))))
</pre>
</div>
<p>
by howardism: [re]open non-writable file with sudo
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defadvice</span> <span style="color: #9932cc;">ido-find-file</span> (after find-file-sudo activate)
<span style="color: #cd6600;">"Find file as root if necessary."</span>
(<span style="color: #0000ff;">unless</span> (<span style="color: #0000ff;">and</span> buffer-file-name
(file-writable-p buffer-file-name))
(<span style="color: #0000ff;">let*</span> ((file-name (buffer-file-name))
(file-root (<span style="color: #0000ff;">if</span> (string-match <span style="color: #ff0000;">"/ssh:</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">[</span><span style="color: #ff0000;">^</span><span style="color: #ff0000;">:]+</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">:</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">.*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">"</span> file-name)
(concat <span style="color: #ff0000;">"/ssh:"</span> (match-string 1 file-name)
<span style="color: #ff0000;">"|sudo:"</span> (match-string 1 file-name)
<span style="color: #ff0000;">":"</span> (match-string 2 file-name))
(concat <span style="color: #ff0000;">"/sudo:localhost:"</span> file-name))))
(find-alternate-file file-root))))
</pre>
</div>
<p>
<i>FIXME</i>: add ido-ignore-files defun.
</p>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org5b9a705" class="outline-4">
<h4 id="org5b9a705"><span class="section-number-4">6.5.10</span> Save cursor position</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-10">
<p>
So the next time I start emacs and open a file I were editing
previously, (point) will be in the exact places where it was
before.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (version&lt; emacs-version <span style="color: #ff0000;">"25.0"</span>)
(<span style="color: #0000ff;">progn</span>
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'saveplace</span>)
(<span style="color: #0000ff;">setq-default</span> save-place t))
(save-place-mode 1))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org84a70ae" class="outline-4">
<h4 id="org84a70ae"><span class="section-number-4">6.5.11</span> DoReMi experimentation</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-11">
<p>
I'm not using it a lot, sometimes I tune the background color though.
</p>
<p>
via <a href="https://www.emacswiki.org/emacs/DoReMi">emacswiki/DoReMi</a>
cool ones: doremi-buffers, doremi-all-faces-fg+ [s, h]
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'doremi</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'doremi-frm</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'doremi-cmd</span>)
</pre>
</div>
<p>
<i>FIXME</i>: find a good key
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'cb</span> <span style="color: #ff00ff;">'doremi-buffers</span>+)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orge147b38" class="outline-4">
<h4 id="orge147b38"><span class="section-number-4">6.5.12</span> Hightligt TABs</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-12">
<p>
not a mode, but however: higlight TABs in certain modes
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defface</span> <span style="color: #a0522d;">extra-whitespace-face</span>
'((t (<span style="color: #8a2be2;">:background</span> <span style="color: #ff0000;">"pale green"</span>)))
<span style="color: #cd6600;">"Used for tabs and such."</span>)
(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">tvd-extra-keywords</span>
'((<span style="color: #ff0000;">"\t"</span> . <span style="color: #ff00ff;">'extra-whitespace-face</span>)))
(add-something-to-mode-hooks '(c c++ vala cperl emacs-lisp python shell-script ruby)
(<span style="color: #0000ff;">lambda</span> () (font-lock-add-keywords nil tvd-extra-keywords)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgc172036" class="outline-4">
<h4 id="orgc172036"><span class="section-number-4">6.5.13</span> Browse kill-ring</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-13">
<p>
when active use n and p to browse, &lt;ret&gt; to select, it's the same
as &lt;M-y&gt; and I never really use it&#x2026;
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'browse-kill-ring</span>)
(<span style="color: #0000ff;">setq</span> browse-kill-ring-highlight-current-entry t
browse-kill-ring-highlight-inserted-item t)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org9f7792a" class="outline-4">
<h4 id="org9f7792a"><span class="section-number-4">6.5.14</span> goto-last-change</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-14">
<p>
Very handy, jump to last change[s].
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'goto-last-change</span>)
(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-b"</span>) <span style="color: #ff00ff;">'goto-last-change</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org8ec5a23" class="outline-4">
<h4 id="org8ec5a23"><span class="section-number-4">6.5.15</span> Bookmarks</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-15">
<p>
I use the builtin bookmark feature quite a lot and am happy with
it. Especially at work, where many files are located in large
path's on remote storage systems, it great to jump quickly to such
places.
</p>
<p>
everytime bookmark is changed, automatically save it
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> bookmark-save-flag 1
bookmark-version-control t)
</pre>
</div>
<p>
I use the same aliases as in apparix for bash (since I'm used to them)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'to</span> <span style="color: #ff00ff;">'bookmark-jump</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'bm</span> <span style="color: #ff00ff;">'bookmark-set</span>)
(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'bl</span> <span style="color: #ff00ff;">'bookmark-bmenu-list</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org43c0494" class="outline-4">
<h4 id="org43c0494"><span class="section-number-4">6.5.16</span> which-key</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-16">
<p>
One of the best unobstrusive modes for key help ever. Just start
entering a key chord, prefix or whatever, and it pops a small
buffer (on the right side in my case) showing the avialable keys to
press from there along with the associated functions.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'which-key</span>)
(which-key-mode)
(which-key-setup-side-window-right)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org97d098a" class="outline-4">
<h4 id="org97d098a"><span class="section-number-4">6.5.17</span> iBuffer mode</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-17">
<p>
iBuffer is a great interactive buffer management tool included with
emacs. I use it with a couple of custom groups, my own
collapse-code (&lt;TAB&gt;) and formats.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'ibuffer</span>)
</pre>
</div>
<p>
from github:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'ibuffer-vc</span>)
(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'ibuffer-tramp</span>)
</pre>
</div>
<p>
replace default list-buffers with ibuffer
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(global-set-key (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"C-x C-b"</span>) <span style="color: #ff00ff;">'ibuffer</span>)
</pre>
</div>
<p>
group name
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> tvd-ibuffer-filter-group-name <span style="color: #ff0000;">"tvd-filters"</span>)
</pre>
</div>
<p>
filter group config
with hints from <a href="https://ogbe.net/emacsconfig.html">Ogbe</a> et.al.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> ibuffer-saved-filter-groups
(list (nreverse
`(
(<span style="color: #ff0000;">"Org"</span> (mode . org-mode))
(<span style="color: #ff0000;">"Shell"</span> (<span style="color: #0000ff;">or</span> (mode . term-mode)
(mode . eshell-mode)
(mode . shell-mode)))
(<span style="color: #ff0000;">"Emacs-Config"</span> (filename . <span style="color: #ff0000;">"emacs"</span>))
(<span style="color: #ff0000;">"Cisco-Config"</span> (mode . cisco-mode))
(<span style="color: #ff0000;">"Code"</span> (<span style="color: #0000ff;">or</span> (mode . cperl-mode)
(mode . c-mode)
(mode . python-mode)
(mode . shell-script-mode)
(mode . makefile-mode)
(mode . cc-mode)))
(<span style="color: #ff0000;">"Text"</span> (<span style="color: #0000ff;">or</span> (mode . text-mode)
(filename . <span style="color: #ff0000;">"\\.pod$"</span>)))
(<span style="color: #ff0000;">"LaTeX"</span> (mode . latex-mode))
(<span style="color: #ff0000;">"Interactive"</span> (<span style="color: #0000ff;">or</span>
(mode . inferior-python-mode)
(mode . slime-repl-mode)
(mode . inferior-lisp-mode)
(mode . inferior-scheme-mode)
(name . <span style="color: #ff0000;">"*ielm*"</span>)))
(<span style="color: #ff0000;">"Crab"</span> (<span style="color: #0000ff;">or</span>
(name . <span style="color: #ff0000;">"^\\*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">Help</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">scratch</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">Messages</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">\\*"</span>)
))
,tvd-ibuffer-filter-group-name))))
</pre>
</div>
<p>
Reverse the order of the filter groups. Kind of confusing: Since
I'm reversing the order of the groups above, this snippet ensures
that the groups are ordered in the way they are written above, with
the "Default" group on top. This advice might need to be ported to
the new advice system soon.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defadvice</span> <span style="color: #9932cc;">ibuffer-generate-filter-groups</span>
(after reverse-ibuffer-groups () activate)
(<span style="color: #0000ff;">setq</span> ad-return-value (nreverse ad-return-value)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">ibuffer-add-dynamic-filter-groups</span> ()
(<span style="color: #0000ff;">interactive</span>)
(<span style="color: #0000ff;">dolist</span> (group (ibuffer-vc-generate-filter-groups-by-vc-root))
(add-to-list <span style="color: #ff00ff;">'ibuffer-filter-groups</span> group))
(<span style="color: #0000ff;">dolist</span> (group (ibuffer-tramp-generate-filter-groups-by-tramp-connection))
(add-to-list <span style="color: #ff00ff;">'ibuffer-filter-groups</span> group)))
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">tvd-ibuffer-hooks</span> ()
(ibuffer-auto-mode 1)
(ibuffer-switch-to-saved-filter-groups tvd-ibuffer-filter-group-name)
(ibuffer-add-dynamic-filter-groups))
(add-hook <span style="color: #ff00ff;">'ibuffer-mode-hook</span> <span style="color: #ff00ff;">'tvd-ibuffer-hooks</span>)
</pre>
</div>
<p>
Only show groups that have active buffers
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> ibuffer-show-empty-filter-groups nil)
</pre>
</div>
<p>
Don't show the summary or headline
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> ibuffer-display-summary nil)
</pre>
</div>
<p>
do not prompt for every action
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> ibuffer-expert t)
</pre>
</div>
<p>
buffers to always ignore
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-to-list <span style="color: #ff00ff;">'ibuffer-never-show-predicates</span> <span style="color: #ff0000;">"^\\*</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">(</span><span style="color: #ff0000;">Completions</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">|</span><span style="color: #ff0000;">tramp/</span><span style="color: #ff0000; font-weight: bold;">\\</span><span style="color: #ff0000; font-weight: bold;">)</span><span style="color: #ff0000;">"</span>)
</pre>
</div>
<p>
Use human readable Size column instead of original one
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">define-ibuffer-column</span> size-h
(<span style="color: #8a2be2;">:name</span> <span style="color: #ff0000;">"Size"</span> <span style="color: #8a2be2;">:inline</span> t)
(<span style="color: #0000ff;">cond</span>
((&gt; (buffer-size) 1000000) (format <span style="color: #ff0000;">"%7.1fM"</span> (/ (buffer-size) 1000000.0)))
((&gt; (buffer-size) 100000) (format <span style="color: #ff0000;">"%7.0fk"</span> (/ (buffer-size) 1000.0)))
((&gt; (buffer-size) 1000) (format <span style="color: #ff0000;">"%7.1fk"</span> (/ (buffer-size) 1000.0)))
(t (format <span style="color: #ff0000;">"%8d"</span> (buffer-size)))))
</pre>
</div>
<p>
Modify the default ibuffer-formats
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq</span> ibuffer-formats
'((mark modified read-only <span style="color: #ff0000;">" "</span>
(name 20 40 <span style="color: #8a2be2;">:left</span> <span style="color: #8a2be2;">:elide</span>)
<span style="color: #ff0000;">" "</span>
(size-h 9 -1 <span style="color: #8a2be2;">:right</span>)
<span style="color: #ff0000;">" "</span>
(mode 16 16 <span style="color: #8a2be2;">:left</span> <span style="color: #8a2be2;">:elide</span>)
<span style="color: #ff0000;">" "</span>
filename-and-process)))
</pre>
</div>
<p>
hide annoying groups, but keep its buffers available
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defvar</span> <span style="color: #a0522d;">ibuffer-collapsed-groups</span> (list <span style="color: #ff0000;">"Crab"</span>))
(advice-add <span style="color: #ff00ff;">'ibuffer</span> <span style="color: #8a2be2;">:after</span> '(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args)
(ignore args)
(<span style="color: #0000ff;">save-excursion</span>
(<span style="color: #0000ff;">dolist</span> (group ibuffer-collapsed-groups)
(<span style="color: #0000ff;">ignore-errors</span>
(ibuffer-jump-to-filter-group group)
(ibuffer-toggle-filter-group))))))
</pre>
</div>
<p>
move point to most recent buffer when entering ibuffer
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defadvice</span> <span style="color: #9932cc;">ibuffer</span> (around ibuffer-point-to-most-recent) ()
<span style="color: #ff0000;">"Open ibuffer with cursor pointed to most recent (non-minibuffer) buffer name"</span>
(<span style="color: #0000ff;">let</span> ((recent-buffer-name
(<span style="color: #0000ff;">if</span> (minibufferp (buffer-name))
(buffer-name
(window-buffer (minibuffer-selected-window)))
(buffer-name (other-buffer)))))
ad-do-it
(ibuffer-jump-to-buffer recent-buffer-name)))
(ad-activate <span style="color: #ff00ff;">'ibuffer</span>)
</pre>
</div>
<p>
override ibuffer M-o binding
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-key ibuffer-mode-map (<span style="color: #0000ff;">kbd</span> <span style="color: #ff0000;">"M-o"</span>) <span style="color: #ff00ff;">'other-window-or-switch-buffer</span>)
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org19822ef" class="outline-4">
<h4 id="org19822ef"><span class="section-number-4">6.5.18</span> Printing</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-18">
<p>
overwrites printing default menu, access via menu File =&gt; Print
or:
</p>
<ul class="org-ul">
<li>M-x ps-spool-buffer-with-faces</li>
<li>go to <b>spool</b> buffer</li>
<li>save to .ps file</li>
<li>print</li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'printing</span>)
(pr-menu-bind)
</pre>
</div>
<p>
via <a href="https://emacs.stackexchange.com/questions/9364/convert-a-text-buffer-to-a-pdf-file">stackoverflow</a>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">when</span> (executable-find <span style="color: #ff0000;">"ps2pdf"</span>)
(<span style="color: #0000ff;">defun</span> <span style="color: #9932cc;">print-to-pdf</span> (<span style="color: #483d8b;">&amp;optional</span> filename)
<span style="color: #cd6600;">"Print file in the current buffer as pdf, including font, color, and</span>
<span style="color: #cd6600;">underline information. This command works only if you are using a window system,</span>
<span style="color: #cd6600;">so it has a way to determine color values.</span>
<span style="color: #cd6600;">C-u COMMAND prompts user where to save the Postscript file (which is then</span>
<span style="color: #cd6600;">converted to PDF at the same location."</span>
(<span style="color: #0000ff;">interactive</span> (list (<span style="color: #0000ff;">if</span> current-prefix-arg
(ps-print-preprint 4)
(concat (file-name-sans-extension (buffer-file-name))
<span style="color: #ff0000;">".ps"</span>))))
(ps-print-with-faces (point-min) (point-max) filename)
(shell-command (concat <span style="color: #ff0000;">"ps2pdf "</span> filename))
(delete-file filename)
(message <span style="color: #ff0000;">"Deleted %s"</span> filename)
(message <span style="color: #ff0000;">"Wrote %s"</span> (concat (file-name-sans-extension filename) <span style="color: #ff0000;">".pdf"</span>))))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orga40232d" class="outline-4">
<h4 id="orga40232d"><span class="section-number-4">6.5.19</span> Beacon mode (pointer blink)</h4>
2020-09-02 20:44:21 +02:00
<div class="outline-text-4" id="text-6-5-19">
<p>
Source: <a href="https://github.com/Malabarba/beacon">beacon mode</a>
</p>
<p>
Blink the cursor shortly when moving across large text sections or
when changing windows. That way it is easier to find the current
editing position.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'beacon</span>)
(<span style="color: #0000ff;">setq</span> beacon-blink-duration 0.1
beacon-blink-when-point-moves-vertically 10
beacon-color 0.3)
(add-hook <span style="color: #ff00ff;">'beacon-dont-blink-predicates</span>
(<span style="color: #0000ff;">lambda</span> () (<span style="color: #0000ff;">bound-and-true-p</span> novel-mode)))
(beacon-mode)
</pre>
</div>
<hr />
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orgfbd2d87" class="outline-3">
<h3 id="orgfbd2d87"><span class="section-number-3">6.6</span> mode-line setup (must be the last mode)</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-6-6">
<p>
I just append the current version of my emacs config and leave out
some stuff to keep the modeline short, so that everything can be
seen even if I have multiple windows open.
</p>
<p>
smaller pos
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq-default</span> mode-line-position
'((-3 <span style="color: #ff0000;">"%p"</span>) (size-indication-mode (<span style="color: #ff0000;">"/"</span> (-4 <span style="color: #ff0000;">"%I"</span>)))
<span style="color: #ff0000;">" "</span>
(line-number-mode
(<span style="color: #ff0000;">"%l"</span> (column-number-mode <span style="color: #ff0000;">":%c"</span>)))))
</pre>
</div>
<p>
when macro recording is active, signal it with coloring instead of
just a character
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defface</span> <span style="color: #a0522d;">rec-face</span>
'((t (<span style="color: #8a2be2;">:background</span> <span style="color: #ff0000;">"red"</span> <span style="color: #8a2be2;">:foreground</span> <span style="color: #ff0000;">"white"</span> <span style="color: #8a2be2;">:weight</span> bold)))
<span style="color: #cd6600;">"Flag macro recording in mode-line"</span>
<span style="color: #8a2be2;">:group</span> <span style="color: #ff00ff;">'tvd-mode-line-faces</span>)
</pre>
</div>
<p>
custom modeline
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">setq-default</span> mode-line-format
(list
<span style="color: #ff0000;">"%e"</span>
mode-line-front-space
mode-line-mule-info
mode-line-modified
mode-line-remote
<span style="color: #ff0000;">" "</span>
mode-line-buffer-identification
<span style="color: #ff0000;">" "</span>
mode-line-position
<span style="color: #ff0000;">" (%m) "</span>
<span style="color: #ff0000;">" ["</span> tvd-emacs-version <span style="color: #ff0000;">"] "</span>
<span style="color: #006400;">; </span><span style="color: #006400;">added because of eyebrowse</span>
mode-line-misc-info
'(<span style="color: #8a2be2;">:eval</span> (propertize
(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">eq</span> defining-kbd-macro t)
<span style="color: #ff0000;">"[REC]"</span>
<span style="color: #ff0000;">""</span>)
<span style="color: #ff00ff;">'face</span> <span style="color: #ff00ff;">'rec-face</span>))
mode-line-end-spaces))
</pre>
</div>
<hr />
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org91a9200" class="outline-2">
<h2 id="org91a9200"><span class="section-number-2">7</span> Emacs Autoconfig / Customize group / final stuff</h2>
2020-09-02 20:44:21 +02:00
<div class="outline-text-2" id="text-7">
<hr />
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-orge918444" class="outline-3">
<h3 id="orge918444"><span class="section-number-3">7.1</span> font faces</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-7-1">
<p>
Font color config, must always be the last thing so all hook faces are loaded.
</p>
<p>
show available colors:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">defalias</span> <span style="color: #ff00ff;">'colors</span> <span style="color: #ff00ff;">'list-colors-display</span>)
</pre>
</div>
<p>
from 20181227 I outsourced my font config into a theme, located in
.emacs.d/tom-past-century.el, so that I can load another theme
anytime I like AND switch back to my own config w/o restarting
emacs
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(add-hook <span style="color: #ff00ff;">'after-init-hook</span> (<span style="color: #0000ff;">lambda</span> () (load-theme <span style="color: #ff00ff;">'tom-past-century</span> t)))
</pre>
</div>
<p>
unless we're on windoze
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">not</span> (null tvd-win-home))
(set-face-font <span style="color: #ff00ff;">'default</span> <span style="color: #ff0000;">"Courier New"</span>))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org0e03ca5" class="outline-3">
<h3 id="org0e03ca5"><span class="section-number-3">7.2</span> emacs server</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-7-2">
<p>
<a href="http://lists.gnu.org/archive/html/bug-gnu-emacs/2018-06/msg00723.html">Based on this</a>
I check both predicates, just to be sure, only one of them doesn't work.
</p>
<p>
<i>FIXME</i>: check if 'server-socket-dir/server exists as well
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #0000ff;">require</span> <span style="color: #ff00ff;">'server</span>)
(<span style="color: #0000ff;">unless</span> (<span style="color: #0000ff;">or</span> (server-running-p)
(<span style="color: #0000ff;">and</span> (boundp <span style="color: #ff00ff;">'server-process</span>) server-process))
(<span style="color: #0000ff;">progn</span>
(advice-add <span style="color: #ff00ff;">'save-buffers-kill-terminal</span> <span style="color: #8a2be2;">:before</span>
(<span style="color: #0000ff;">lambda</span> (<span style="color: #483d8b;">&amp;rest</span> args) (server-edit)))
(server-start)))
</pre>
</div>
<hr />
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org0a9ba17" class="outline-3">
<h3 id="org0a9ba17"><span class="section-number-3">7.3</span> variables</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-7-3">
<p>
If I ever use custom-group to customize a mode, then I create a
manual config section for it using the values, custom has added
here. So, in normal times this should be empty, but needs to exist.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(custom-set-variables
<span style="color: #006400;">;; </span><span style="color: #006400;">custom-set-variables was added by Custom.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">If you edit it by hand, you could mess it up, so be careful.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">Your init file should contain only one such instance.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">If there is more than one, they won't work right.</span>
'(custom-safe-themes
(<span style="color: #0000ff;">quote</span>
(<span style="color: #ff0000;">"d88c43fe03ac912e35963695caf0ae54bc6ce6365c3a42da434ef639f7a37399"</span> default)))
'(package-selected-packages (<span style="color: #0000ff;">quote</span> (magit)))
'(safe-local-variable-values (<span style="color: #0000ff;">quote</span> ((ruby-indent-level 4)))))
</pre>
</div>
</div>
</div>
2021-05-01 13:15:16 +02:00
<div id="outline-container-org669ec72" class="outline-3">
<h3 id="org669ec72"><span class="section-number-3">7.4</span> done</h3>
2020-09-02 20:44:21 +02:00
<div class="outline-text-3" id="text-7-4">
<p>
Finally, this message is being displayed. If this isn't the case I
know easily that something went wrong.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(message <span style="color: #ff0000;">"loading done"</span>)
(custom-set-faces
<span style="color: #006400;">;; </span><span style="color: #006400;">custom-set-faces was added by Custom.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">If you edit it by hand, you could mess it up, so be careful.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">Your init file should contain only one such instance.</span>
<span style="color: #006400;">;; </span><span style="color: #006400;">If there is more than one, they won't work right.</span>
)
</pre>
</div>
</div>
</div>
</div>
2017-06-17 18:58:04 +02:00
</div>
<div id="postamble" class="status">
2017-09-01 07:51:06 +02:00
<p class="author">Author: Tom</p>
2021-05-01 13:15:16 +02:00
<p class="date">Created: 2021-05-01 Sa 13:15</p>
2017-06-17 18:58:04 +02:00
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>