-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmacs-Learning.html
209 lines (196 loc) · 15 KB
/
Emacs-Learning.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16" />
<title>Emacs Learning - SPK's Rationality Essays</title>
<link rel="stylesheet" type="text/css" href="./css/default.css" />
<link rel="stylesheet" type="text/css" href="./css/highlight.css" />
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> -->
<!-- <script type="text/javascript" src="/js/header-links.js"></script> -->
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link href="atom.xml" type="application/atom+xml" rel="alternate" title="Sitewide ATOM/RSS Feed" />
<!-- Google Analytics stuff -->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DEWF2J5BG8"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DEWF2J5BG8');
</script>
<script type="text/javascript" src="https://fast.fonts.net/jsapi/f7f47a40-b25b-44ee-9f9c-cfdfc8bb2741.js"></script>
</head>
<body>
<div id="header">
<div id="logo">
<a href="./">SPK's Rationality Essays</a>
</div>
<div id="navigation">
<a href="./">Home</a>
<a href="./notes.html">Notes</a>
<!-- <a href="/about.html">About</a> -->
<a href="./archive.html">Archive</a>
<a href="./atom.xml" type="application/atom+xml" rel="alternate" title="Sitewide ATOM/RSS Feed">RSS</a>
</div>
</div>
<div id="content">
<h1 id="post-title">Emacs Learning</h1>
<!-- <center><img src="https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-prn1/t31.0-8/p600x600/10257116_10202295769100492_2438594605053717342_o.jpg" height="400" width="300" class="sujeet-pic" alt="Sujeet pic" /></center> -->
<h1 id="docstring">Docstring</h1>
<p>I think you shouldn’t leave a blank line between the first line of the docstring and the next. I wrote all my elisp functions like that for the last four years :P</p>
<h1 id="shell">Shell</h1>
<ul>
<li><p>TODO Get the Emacs shell to have proper PATH and completion (maybe)</p>
<p>sum-column should work</p></li>
</ul>
<h1 id="dired">Dired</h1>
<p>Q on marked buffers seems to crash Emacs at the end. It has happened five times now (in my website directory).</p>
<h1 id="emacs-lisp-hacking">Emacs Lisp Hacking</h1>
<p>Check out <code>testcover</code> or <code>edebug</code> for test coverage.</p>
<h1 id="dired-1">Dired</h1>
<p>wdired: When doing <code>query-replace-regexp</code> on the file names, you have to be careful not to match anything other than the filename. Otherwise, you match some of the permission data or the owner data, which are read only. And since <code>query-replace-skip-read-only</code> is on, <code>query-replace-regexp</code> skips those matches.</p>
<h1 id="dot-emacs">Dot Emacs</h1>
<p>“Never use load or require” - <a href="http://a-nickels-worth.blogspot.in/2007/11/effective-emacs.html">Effective .emacs</a>. He recommends using <code>autoload</code> and <code>eval-after-load</code> instead.</p>
<h1 id="magit">Magit</h1>
<blockquote>
<p>Almost all the actions you can carry out in Magit is done through a one-key system that opens up a “command console” window at the bottom, letting you further refine your command before you carry it out. This is a fantastically well-done interface and is probably the killer feature that makes Magit so great. I like it so much that I have copied the underlying interface code for use in some of my own Emacs hackery. It’s really, really nice.</p>
<p>– <a href="https://www.masteringemacs.org/article/introduction-magit-emacs-mode-git">Mastering Emacs</a></p>
</blockquote>
<h2 id="annoying-reverting-of-buffers-with-uncommitted-changes">Annoying Reverting of Buffers with Uncommitted Changes</h2>
<p>[2018-12-31 Mon] When I edit and save some file and then commit some other file in the repository (using VC Git or Magit), then when I go back to the first buffer, it asks me to revert the buffer because it seems to have changed on disk.</p>
<p>It happens even when the first buffer has disabled <code>magit-auto-revert-mode</code>.</p>
<h1 id="helm">Helm</h1>
<p>Looks awesome! I had my reservations, but it’s blowing my mind with the consistent interface to my files, buffers, bookmarks, imenu items, man entries, etc.</p>
<h1 id="haskell">Haskell</h1>
<p>Get <a href="http://www.mew.org/~kazu/proj/ghc-mod/en/preparation.html">ghc-mode</a>.</p>
<p>Also <a href="https://www.reddit.com/r/haskell/comments/3kr6m3/update_i_got_spacemacs_working_using_stack_with/">other</a> cool haskell stuff.</p>
<p>Structured Haskell Mode is pretty sweet. It lets you do paredit-like edits, such as going from</p>
<pre><code>hGetContents =<< openFile [cursor]"dictionary.txt" ReadMode</code></pre>
<p>to</p>
<pre><code>"dictionary.txt"</code></pre>
<h1 id="scala">Scala</h1>
<h2 id="ensime">Ensime</h2>
<p><code>C-c C-b t</code> runs all tests. But I can do that on every save using <code>~test</code> or <code>~testQuick</code> in sbt. Why is this better? Even <code>C-c C-b q</code>, which runs just changed tests, takes around 2 seconds, which is the same as for <code>~testQuick</code> in sbt. Maybe it’s easier on your CPU.</p>
<p>Found that if I ran <code>~testQuick</code> in the <code>*sbt*</code> buffer, I couldn’t exit from it. Weird.</p>
<p>What else does Ensime do? It adds semantic highlighting (which I don’t really need), gives you code completion (which might be useful), and some refactoring support (which I will again probably not use). I don’t know if it will be worth it. Let’s see.</p>
<h1 id="screen-lag-in-large-markdown-buffers">Screen Lag in Large Markdown Buffers</h1>
<p>The screen definitely lags when I type in a Markdown buffer with ~24k words, but not when I narrow the buffer to just one small section of 34 words.</p>
<p>Could be because I have large paragraphs (which look to Emacs like large lines). Or it could just be the size of the buffer.</p>
<p>(I think a similar effect occurs even in smaller Markdown buffers.)</p>
<h1 id="markdown-forward-paragraph-leading-spaces-hang">Markdown + forward-paragraph + leading spaces = Hang</h1>
<p><strong>Experiment</strong>: Took a new markdown buffer. Wrote “foo”.</p>
<ul>
<li><p>Added 20 spaces in front of it. Significant lag, especially when moving point. But I’m able to type afterwards.</p></li>
<li><p>Added 35 spaces. Hung.</p></li>
</ul>
<p><strong>Observation</strong>: The word count indicator in the mode line was absent when I pressed C-g to stop Emacs hanging.</p>
<p><strong>Hypothesis</strong>: Could it be because of <code>wc-mode</code>?</p>
<p><strong>Experiment</strong>: You bet!</p>
<ul>
<li>Turned it off. Added 100 spaces. No problem.</li>
</ul>
<p><code>wc-mode</code> calls <code>count-words-in-paragraph</code>. Is it because of that function? Yup.</p>
<p>It hangs when I say <code>(count-words-in-paragraph)</code> near the line with leading spaces.</p>
<p>It’s mark-paragraph that hangs!</p>
<p>Digging further: it’s forward-paragraph that hangs!</p>
<p>All this because of one observation - the word count stat in the mode-line was missing!</p>
<p><strong>Experiment</strong>: The above doesn’t happen with a <code>text-mode</code> buffer with <code>wc-mode</code> turned on.</p>
<p>So, the problem is with <code>forward-paragraph</code> in Markdown.</p>
<p><strong>Experiment</strong>: A long sequence of spaces <em>anywhere</em> is a problem.</p>
<ul>
<li>23 spaces between “fo” and “o” hangs Markdown.</li>
</ul>
<h1 id="ispell">Ispell</h1>
<p>Set your personal dictionary file so that your words are saved.</p>
<pre><code>(setq ispell-personal-dictionary "~/.ispell_pradeep_laptop")</code></pre>
<h1 id="upgrading-from-emacs-24.3-to-25.3">Upgrading from Emacs 24.3 to 25.3</h1>
<p>What still doesn’t work:</p>
<p>log-edit-done - doesn’t show diff and fails when I try to commit.</p>
<pre><code>log-edit-show-diff: Diff functionality has not been setup
Wrong type argument: commandp, nil</code></pre>
<p>This is because of the following code in log-edit.el.gz:</p>
<pre><code>(defvar log-edit-callback nil)
(defvar log-edit-diff-function nil)</code></pre>
<p>I’m guessing that Git backend support has somehow not been set up.</p>
<p>[2018-01-04 Thu] Haven’t had any such problems since then. Don’t know why.</p>
<h1 id="writing-your-own-elisp-packages">Writing your own Elisp Packages</h1>
<p>I wrote <code>org-autoclock.el</code>. It’s not yet a package that can be installed via the package manager, but it is a working standalone file.</p>
<p>But I failed to require <code>org</code> and <code>s</code> and <code>f</code>, which the code needed and which worked in my setup because I had already required them. So, naturally, when my friend tried to use <code>org-autoclock</code>, it blew up. Bad.</p>
<p><strong>Lesson</strong>: Run your proposed elisp code in an isolated Emacs instance so that you see which dependencies you need.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">emacs</span> -Q -l org-autoclock.el</code></pre></div>
<p>Observation: When Emacs doesn’t know the definition of some function, it just skips it or something.</p>
<h1 id="opening-files-as-root">Opening Files as Root</h1>
<p>To manipulate a file (say <code>/etc/apt/sources.list</code>) with sudo permissions:</p>
<pre><code># ido will provide completion.
C-x C-f RET /sudo:root@localhost:/etc/apt/sources.list/</code></pre>
<h1 id="calc">Calc</h1>
<h2 id="recompute-an-expression-for-different-values">Recompute an Expression for Different Values</h2>
<p>To calculate the compound interest formula <code>a * (1 + r / 100)^t</code> for different values of r and t and a, do</p>
<pre><code>'a * (1 + r/100)^t =></code></pre>
<p>The <code>=></code> tells Calc that you want it to recompute that expression every time you set a value to one of its variables.</p>
<p>So, you can do</p>
<pre><code>ss a = 3336
ss t = 10
ss r = 10</code></pre>
<p>to see</p>
<pre><code>1: a*(r / 100 + 1)^t => 8652.72484689</code></pre>
<p>Change the rate r</p>
<pre><code>ss r = 20</code></pre>
<p>to see</p>
<pre><code>1: a*(r / 100 + 1)^t => 20655.6327051</code></pre>
<h2 id="financial-functions">Financial functions</h2>
<p>h/t: Andrew Hyatt’s post at https://plus.google.com/+AndrewHyatt/posts/YdwsbNmZ4NL</p>
<p>The examples are from the excellent Emacs Calc manual. And, yes, they were right - I suddenly got a better grasp of present value after reading the manual pages (8.6.3 Present Value)</p>
<p>If you start out with a lump sum of $6479 and get 9% interest for 4 years, you would end up with a final amount of $9146. So, the “future value of a lump sum” of $6479 at 9% after 4 years is $9146.</p>
<pre><code>fvl(9%, 4, 6479.44) => 9146.2583471</code></pre>
<p>If get $2000 each year from an investment (and then put it in a bank at 9%) for 4 years, you would have to start out with $6479 to get what that would earn in 4 years from something earning 9% interest. Put differently, the “present value of benefits” of $2000 each year for 4 years at an interest rate of 9% is $6479.</p>
<pre><code>pv(9%, 4, 2000) => 6479.44</code></pre>
<p>If you pay $2000 each year for 4 years and get 9% interest, then your final amount would be $9146. This is probably “future value of installments”.</p>
<pre><code>fv(9%, 4, 2000) => 9146.258</code></pre>
<p>If you take a loan of $6479 right now, you would have to pay $2000 each year so that the lender would get that much at the end of 4 years by saving it from the beginning at 9%. Basically, the present value of your periodic payments is $6479. Use <code>pmt</code> to calculate the periodic payments.</p>
<pre><code>pmt(9%, 4, 6479.44) => 2000.0000759</code></pre>
<p>Number of periodic payments needed to make the present value of $2000 per year equal $6479: use <code>nper</code>.</p>
<pre><code>nper(9%, 2000, 6479) => 3.99967586385</code></pre>
<p>Rate at which you would have got a present value of $6479 from payments of $2000 for 4 years: use <code>rate</code>.</p>
<pre><code>rate(4, 2000, 6479) => 0.0900309222001 (9%)</code></pre>
<p>Rate at which you would get $9146 from a lump sum $6479 after 4 years: use <code>ratel</code>.</p>
<pre><code>ratel(4, 9146, 6479) => 0.0900108081676 (9%)</code></pre>
<p>Net present value of a series of irregular investments when you could have invested them at 9%: use <code>npv</code>. (Here I’m copying the example for 4 equal payments of $2000.)</p>
<pre><code>npv(9%, [2000, 2000, 2000, 2000]) => 6479.43975411</code></pre>
<p>Rate of interest that would have got you the same final amount as a bunch of irregular payments: use <code>irr</code>.</p>
<pre><code>[ERROR - Don't know why.]
Unable to bracket root: (1e-4 .. 199261560.80331)</code></pre>
<h2 id="useful-links">Useful links</h2>
<p>http://nullprogram.com/blog/2009/06/23/ - Walks you through useful Calc commands - data formats like hex, complex numbers, HMS; matrix division; plotting graphs with a few keystrokes!; unit conversion.</p>
<p>https://truongnghiem.wordpress.com/common-calculations-in-emacscalc/ - showed me how to automatically recompute an expression by setting different values to a variable.</p>
<div class="info">Created: August 6, 2015</div>
<div class="info">Last modified: September 28, 2019</div>
<div class="info">Status: in-progress notes</div>
<div class="info"><b>Tags</b>: notes, emacs</div>
<br />
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'spkrationalitytrainingground'; // required: replace example with your forum shortname
var disqus_identifier = '/Emacs-Learning.html';
var disqus_title = 'Emacs Learning';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<script type="text/javascript" src="https://fast.fonts.net/jsapi/f7f47a40-b25b-44ee-9f9c-cfdfc8bb2741.js"></script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<div id="footer">
Site proudly generated by
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
</div>
</body>
</html>