23 lines
1.4 KiB
Plaintext
23 lines
1.4 KiB
Plaintext
<p>
|
|
Over the years, i've written perhaps hundreds of little emacs
|
|
commands. Most of them looked useful at the time (why, i absolutely
|
|
<i>needed</i> them!), but just faded away after a few weeks. There are a
|
|
handful though that i use all the time, and i specially like it when
|
|
their signal (features, usefulness) to noise (lines of code) ratio is
|
|
above average. Here's one with a surprisingly high one:
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-emacs-lisp">(<span style="color: #023770;">defun</span> <span style="color: #005555;">jao-buffer-same-mode</span> (&rest modes)
|
|
<span style="color: #626262; font-style: italic;">"Pop to a buffer with a mode among MODES, or the current one if not given."</span>
|
|
(<span style="color: #023770;">interactive</span>)
|
|
(<span style="color: #023770;">let*</span> ((modes (<span style="color: #023770;">or</span> modes (list major-mode)))
|
|
(pred (<span style="color: #023770;">lambda</span> (b)
|
|
(<span style="color: #023770;">let</span> ((b (get-buffer (<span style="color: #023770;">if</span> (consp b) (car b) b))))
|
|
(member (buffer-local-value 'major-mode b) modes)))))
|
|
(pop-to-buffer (read-buffer <span style="color: #00552a;">"Buffer: "</span> nil t pred))))
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="taglist"><a href="https://jao.io/blog/tags.html">Tags</a>: <a href="https://jao.io/blog/tag-emacs.html">emacs</a> </div> |