-
Notifications
You must be signed in to change notification settings - Fork 1
/
2012-10-14-emacs-customizations.html
191 lines (172 loc) · 8.23 KB
/
2012-10-14-emacs-customizations.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="alternate"
type="application/rss+xml"
href="https://bastibe.de/rss.xml"
title="RSS feed for https://bastibe.de/">
<title>My Emacs customizations</title>
<meta name="author" content="Bastian Bechtold">
<meta name="referrer" content="no-referrer">
<link href= "static/style.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="static/favicon.ico">
<link rel="apple-touch-icon-precomposed" href="static/favicon-152.png">
<link rel="msapplication-TitleImage" href="static/favicon-144.png">
<link rel="msapplication-TitleColor" href="#0141ff">
<script src="static/katex.min.js"></script>
<script src="static/auto-render.min.js"></script>
<script src="static/lightbox.js"></script>
<link rel="stylesheet" href="static/katex.min.css">
<script>document.addEventListener("DOMContentLoaded", function() { renderMathInElement(document.body); });</script>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
<meta name="viewport" content="initial-scale=1,width=device-width,minimum-scale=1"></head>
<body>
<div id="preamble" class="status"><div class="header">
<a href="https://bastibe.de">Basti's Scratchpad on the Internet</a>
<div class="sitelinks">
<a href="https://github.com/bastibe">Github</a> | <a href="https://bastibe.de/projects.html">Projects</a> | <a href="https://bastibe.de/uses.html">Uses</a> | <a href="https://bastibe.de/reviews.html">Reviews</a> | <a href="https://bastibe.de/about.html">About</a>
</div>
</div></div>
<div id="content">
<div class="post-date">14 Oct 2012</div><h1 class="post-title"><a href="https://bastibe.de/2012-10-14-emacs-customizations.html">My Emacs customizations</a></h1>
<p>
I don't host my <code>.emacs</code> in a repository. I tried it for a while, but it did not work for me. I think repos are great for managing multiple divergent versions of the same source tree. However, my dotfiles should never diverge, they should just be kept in sync. This is what Dropbox is great at. So I use Dropbox instead of git.
</p>
<p>
One downside of that is that it is not as easy to provide a public link to my dotfiles. Or maybe it is. Here goes
</p>
<p>
<a href="https://bitbucket.org/bastibe/.emacs.d/src/">My <i>.emacs</i></a>
</p>
<p>
Now on to the meat of this post: Some customizations I made that I think are cool.
</p>
<div id="outline-container-org2cd85e7" class="outline-2">
<h2 id="org2cd85e7">When Emacs starts up, make it fit the left half of the screen</h2>
<div class="outline-text-2" id="text-org2cd85e7">
<p>
First, I need a function to set the size of a frame in terms of pixels. Emacs only provides <code>set-frame-size</code>, but that works on characters, not pixels.
</p>
<div class="org-src-container">
<pre class="src src-elisp">(defun set-frame-pixel-size (frame width height)
"Sets size of FRAME to WIDTH by HEIGHT, measured in pixels."
(let ((pixels-per-char-width (/ (frame-pixel-width) (frame-width)))
(pixels-per-char-height (/ (frame-pixel-height) (frame-height))))
(set-frame-size frame
(floor (/ width pixels-per-char-width))
(floor (/ height pixels-per-char-height)))))
</pre>
</div>
<p>
Next, a function that uses the above to set the frame size to exactly fit the left half of the screen. Note that the <code>excess-...</code> variables account for things like the menu bar, the dock or the task bar so you might have to adapt these values to your particular windowing environment. The values given here work for dockless OSX.
</p>
<div class="org-src-container">
<pre class="src src-elisp">(defun use-left-half-screen ()
(interactive)
(let* ((excess-width 32)
(excess-height 48)
(half-screen-width (- (/ (x-display-pixel-width) 2) excess-width))
(screen-height (- (x-display-pixel-height) excess-height)))
(set-frame-pixel-size (selected-frame) half-screen-width screen-height)))
</pre>
</div>
<p>
Finally, when Emacs starts up, make it use half the screen. Just how I like it!
</p>
<div class="org-src-container">
<pre class="src src-elisp">(if window-system
(use-left-half-screen))
</pre>
</div>
</div>
</div>
<div id="outline-container-org672f606" class="outline-2">
<h2 id="org672f606">Make shell split windows auto-resize</h2>
<div class="outline-text-2" id="text-org672f606">
<p>
Usually when you open a new split window in Emacs, it takes up half the frame. For some kinds of windows, I like them to be smaller. So here is a little snippet that shrinks some kinds of windows to 15 lines of height.
</p>
<div class="org-src-container">
<pre class="src src-elisp">(add-hook 'window-configuration-change-hook
(lambda ()
(when (or (string-equal (buffer-name) "*Python*")
(string-equal (buffer-name) "*eshell*")
(string-equal (buffer-name) "*tex-shell*"))
(if (not (eq (window-height) 15))
(enlarge-window (- 15 (window-height)))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf7592ef" class="outline-2">
<h2 id="orgf7592ef">Create a new line above/below the current one</h2>
<div class="outline-text-2" id="text-orgf7592ef">
<p>
There is one feature of Vim that I really missed: <code>o~/~O</code>, which 'opens' a new line above or below the current one without changing the current line.
</p>
<div class="org-src-container">
<pre class="src src-elisp">(defun vi-open-line-above ()
"Insert a newline above the current line and put point at beginning."
(interactive)
(unless (bolp)
(beginning-of-line))
(newline)
(forward-line -1)
(indent-according-to-mode))
(defun vi-open-line-below ()
"Insert a newline below the current line and put point at beginning."
(interactive)
(unless (eolp)
(end-of-line))
(newline-and-indent))
(global-set-key (kbd "C-o") 'vi-open-line-below)
(global-set-key (kbd "M-o") 'vi-open-line-above)
</pre>
</div>
</div>
</div>
<div id="outline-container-org5c6249d" class="outline-2">
<h2 id="org5c6249d">When editing LaTeX, show PDF output in Emacs</h2>
<div class="outline-text-2" id="text-org5c6249d">
<p>
Emacs provides an awesome mode for editing LaTeX files. But isn't it sad that you always have to leave Emacs for viewing the PDF? Well, not any more.
</p>
<p>
This function will open or refresh a split window with the generated PDF file in it. Thus, when I edit LaTeX, I will hit C-c C-c to compile, then C-c C-v to see the PDF. All that without having to leave the LaTeX file.
</p>
<div class="org-src-container">
<pre class="src src-elisp">;; open/show pdf file within Emacs using doc-view-mode
(defun open-show-pdf ()
(interactive)
(let ((tex-buffer-name (buffer-name))
(pdf-buffer-name (concat (TeX-master-file) ".pdf")))
(if (get-buffer pdf-buffer-name)
(switch-to-buffer-other-window pdf-buffer-name)
(find-file-other-window pdf-buffer-name))
(if (not (eq major-mode 'doc-view-mode))
(doc-view-mode))
(doc-view-revert-buffer t t)
(switch-to-buffer-other-window tex-buffer-name)))
(add-hook 'LaTeX-mode-hook
(lambda ()
(define-key LaTeX-mode-map (kbd "C-c C-v") 'open-show-pdf)
(visual-line-mode t)
(turn-on-reftex))
t)
</pre>
</div>
</div>
</div>
<div class="taglist"><a href="https://bastibe.de/tags.html">Tags</a>: <a href="https://bastibe.de/tag-emacs.html">emacs</a> </div>
<div id="comments"><script async src="https://talk.hyvor.com/embed/embed.js" type="module"></script>
<hyvor-talk-comments id="hyvorcomments" website-id="3390" page-id=""></hyvor-talk-comments>
<script type="text/javascript">
document.getElementById("hyvorcomments").setAttribute("page-id", location.pathname);
</script></div></div>
<div id="postamble" class="status"><div id="archive">
<a href="https://bastibe.de/archive.html">Other posts</a>
</div>
<center><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br /><span xmlns:dct="https://purl.org/dc/terms/" href="https://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">bastibe.de</span> by <a xmlns:cc="https://creativecommons.org/ns#" href="https://bastibe.de" property="cc:attributionName" rel="cc:attributionURL">Bastian Bechtold</a> is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</center></div>
</body>
</html>