snipt

Ctrl+h for KB shortcuts

Common Lisp

convert org-mode date format to simple format

1
2
3
4
5
6
7
;; Converts org-mode style date [2010-10-11 Mon] to simple common format Mon 10/11   
;; Run with cursor after ]
(fset 'org-friendly-date
   [backspace ?\C-  left left left ?\C-w backspace left left left left left backspace backspace backspace backspace backspace backspace ?\C-y ?  right right right backspace ?/ right right])

(fset 'org-friendly-datetime
   [backspace left left left left left left left left left left left left backspace ?/ left left left backspace backspace backspace backspace backspace backspace right right right right right right right right right right right right right right right])
https://snipt.net/embed/93e731e7f865843b6f0839f4cec1b5cc/
https://snipt.net/raw/93e731e7f865843b6f0839f4cec1b5cc/
93e731e7f865843b6f0839f4cec1b5cc
common-lisp
Common Lisp
7
2016-09-20T14:32:48
True
False
False
/api/public/snipt/36722/
convert-org-mode-date-format-to-simple-format
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">;; Converts org-mode style date [2010-10-11 Mon] to simple common format Mon 10/11 </span> </span><span id="L-2"><a name="L-2"></a><span class="c1">;; Run with cursor after ]</span> </span><span id="L-3"><a name="L-3"></a><span class="p">(</span><span class="nv">fset</span> <span class="ss">&#39;org-friendly-date</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">[backspace</span> <span class="nv">?\C-</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">?\C-w</span> <span class="nv">backspace</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">?\C-y</span> <span class="nv">?</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">backspace</span> <span class="nv">?/</span> <span class="nv">right</span> <span class="nv">right]</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="p">(</span><span class="nv">fset</span> <span class="ss">&#39;org-friendly-datetime</span> </span><span id="L-7"><a name="L-7"></a> <span class="nv">[backspace</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">backspace</span> <span class="nv">?/</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">left</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">backspace</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right</span> <span class="nv">right]</span><span class="p">)</span> </span></pre></div> </td></tr></table>
emacs, org-mode

Text only

emacs spaces instead of tabs

1
2
3
4
5
6
7
#To force Emacs to insert spaces instead of tabs when you press the TAB key:

M-x set-variable<RET> indent-tabs-mode<RET> nil

#Or in your .emacs file:

(setq-default indent-tabs-mode nil)
https://snipt.net/embed/4c57f3e6a8cff8a5de5185fade1d7b0f/
https://snipt.net/raw/4c57f3e6a8cff8a5de5185fade1d7b0f/
4c57f3e6a8cff8a5de5185fade1d7b0f
text
Text only
7
2016-09-10T13:34:31
True
False
False
/api/public/snipt/35841/
emacs-spaces-instead-of-tabs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>#To force Emacs to insert spaces instead of tabs when you press the TAB key: </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>M-x set-variable&lt;RET&gt; indent-tabs-mode&lt;RET&gt; nil </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>#Or in your .emacs file: </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>(setq-default indent-tabs-mode nil) </span></pre></div> </td></tr></table>
emacs

Bash

emacs replace

M-x replace-regex notices the user, with "Note: `\n' here doesn't match a newline; to do that, type C-q C-j instead", if you enter `\n' in the search regular expression (but not in the replacement regular expression).
https://snipt.net/embed/3e277121d7f938ef156acf428499bc43/
https://snipt.net/raw/3e277121d7f938ef156acf428499bc43/
3e277121d7f938ef156acf428499bc43
bash
Bash
1
2016-09-24T01:34:05
True
False
False
/api/public/snipt/29357/
emacs-replace-1
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>M-x replace-regex notices the user, with <span class="s2">&quot;Note: `\n&#39; here doesn&#39;t match a newline; to do that, type C-q C-j instead&quot;</span>, <span class="k">if</span> you enter <span class="sb">`</span><span class="se">\n</span><span class="err">&#39;</span> in the search regular expression <span class="o">(</span>but not in the replacement regular expression<span class="o">)</span>. </span></pre></div> </td></tr></table>
emacs

Text only

emacs replace

1
2
3
4
    M-% [Search and Replace]
    C-q C-m [search for quoted character ^M (carriage return)]
    C-q C-j [replace with quoted character ^J (line feed)]
    ! [replace all]
https://snipt.net/embed/78b76a6afb0b33a79609027c7fb46644/
https://snipt.net/raw/78b76a6afb0b33a79609027c7fb46644/
78b76a6afb0b33a79609027c7fb46644
text
Text only
4
2016-09-20T01:46:56
True
False
False
/api/public/snipt/28300/
emacs-replace
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a> M-% [Search and Replace] </span><span id="L-2"><a name="L-2"></a> C-q C-m [search for quoted character ^M (carriage return)] </span><span id="L-3"><a name="L-3"></a> C-q C-j [replace with quoted character ^J (line feed)] </span><span id="L-4"><a name="L-4"></a> ! [replace all] </span></pre></div> </td></tr></table>
emacs

Common Lisp

make zap-to-char act like zap-up-to-char

1
2
3
4
5
(defadvice zap-to-char (after my-zap-to-char-advice (arg char) activate)
  "Kill up to the ARG'th occurence of CHAR, and leave CHAR.
  The CHAR is replaced and the point is put before CHAR."
  (insert char)
  (forward-char -1))
https://snipt.net/embed/85fab756b5be218a607e43cfb26350d0/
https://snipt.net/raw/85fab756b5be218a607e43cfb26350d0/
85fab756b5be218a607e43cfb26350d0
common-lisp
Common Lisp
5
2016-09-24T05:11:55
True
False
False
/api/public/snipt/27688/
make-zap-to-char-act-like-zap-up-to-char
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="p">(</span><span class="nv">defadvice</span> <span class="nv">zap-to-char</span> <span class="p">(</span><span class="nv">after</span> <span class="nv">my-zap-to-char-advice</span> <span class="p">(</span><span class="nv">arg</span> <span class="nb">char</span><span class="p">)</span> <span class="nv">activate</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a> <span class="s">&quot;Kill up to the ARG&#39;th occurence of CHAR, and leave CHAR.</span> </span><span id="L-3"><a name="L-3"></a><span class="s"> The CHAR is replaced and the point is put before CHAR.&quot;</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">(</span><span class="nv">insert</span> <span class="nb">char</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">(</span><span class="nv">forward-char</span> <span class="mi">-1</span><span class="p">))</span> </span></pre></div> </td></tr></table>
elisp, emacs, lisp

Common Lisp

delete current file and buffer

1
2
3
4
5
(defun delete-file-and-buffer ()
  "Deletes the current file and buffer, assumes file exists"
  (interactive)
  (delete-file buffer-file-name)
  (kill-buffer (buffer-name)))
https://snipt.net/embed/1b964a75e08d89620be57b596f6e5f31/
https://snipt.net/raw/1b964a75e08d89620be57b596f6e5f31/
1b964a75e08d89620be57b596f6e5f31
common-lisp
Common Lisp
5
2016-09-24T05:11:59
True
False
False
/api/public/snipt/27687/
deletes-current-file-and-buffer
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="p">(</span><span class="nb">defun</span> <span class="nv">delete-file-and-buffer</span> <span class="p">()</span> </span><span id="L-2"><a name="L-2"></a> <span class="s">&quot;Deletes the current file and buffer, assumes file exists&quot;</span> </span><span id="L-3"><a name="L-3"></a> <span class="p">(</span><span class="nv">interactive</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">(</span><span class="nb">delete-file</span> <span class="nv">buffer-file-name</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">(</span><span class="nv">kill-buffer</span> <span class="p">(</span><span class="nv">buffer-name</span><span class="p">)))</span> </span></pre></div> </td></tr></table>
elisp, emacs, lisp

Common Lisp

repeat text n times - useful in the emacs editor

1
2
3
4
5
6
7
8
(defun text-repeat (n)
  "Insert a block of text,repeated n times."
  (interactive "p")
  (progn
    (insert "the text to repeat\n")
    (cond ((> n 1) (text-repeat (- n 1))))))

(define-key global-map [f7] 'text-repeat)
https://snipt.net/embed/981842e4e0807173bb21b6dfa62dc0d8/
https://snipt.net/raw/981842e4e0807173bb21b6dfa62dc0d8/
981842e4e0807173bb21b6dfa62dc0d8
common-lisp
Common Lisp
8
2016-09-24T05:12:06
True
False
False
/api/public/snipt/26953/
repeat-text-n-times
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="p">(</span><span class="nb">defun</span> <span class="nv">text-repeat</span> <span class="p">(</span><span class="nv">n</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a> <span class="s">&quot;Insert a block of text,repeated n times.&quot;</span> </span><span id="L-3"><a name="L-3"></a> <span class="p">(</span><span class="nv">interactive</span> <span class="s">&quot;p&quot;</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">(</span><span class="k">progn</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">(</span><span class="nv">insert</span> <span class="s">&quot;the text to repeat\n&quot;</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">(</span><span class="nb">cond</span> <span class="p">((</span><span class="nb">&gt;</span> <span class="nv">n</span> <span class="mi">1</span><span class="p">)</span> <span class="p">(</span><span class="nv">text-repeat</span> <span class="p">(</span><span class="nb">-</span> <span class="nv">n</span> <span class="mi">1</span><span class="p">))))))</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="p">(</span><span class="nv">define-key</span> <span class="nv">global-map</span> <span class="nv">[f7]</span> <span class="ss">&#39;text-repeat</span><span class="p">)</span> </span></pre></div> </td></tr></table>
elisp, emacs, lisp, recursion

JavaScript

Strip Ctrl M in emacs

C-x RET f unix RET
https://snipt.net/embed/6819a9d205223730352bf2d8e966acfa/
https://snipt.net/raw/6819a9d205223730352bf2d8e966acfa/
6819a9d205223730352bf2d8e966acfa
js
JavaScript
1
2016-09-22T05:09:00
True
False
False
/api/public/snipt/26424/
strip-ctrl-m-in-emacs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nx">C</span><span class="o">-</span><span class="nx">x</span> <span class="nx">RET</span> <span class="nx">f</span> <span class="nx">unix</span> <span class="nx">RET</span> </span></pre></div> </td></tr></table>
emacs
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.