Skip to content

Instantly share code, notes, and snippets.

;; By Stefan Monnier <foo at acm.org>. It is the opposite of
;; fill-paragraph: Takes a multi-line paragraph and makes it into a
;; single line of text.
(global-set-key (kbd "C-c u") 'unfill-paragraph)
(defun unfill-paragraph ()
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(defadvice package-install (around ad-sheik-package-install activate)
"Run package install, but ignore errors."
(ignore-errors
ad-do-it))
$ echo fnord > fnord
$ (echo foo ; sleep 5 ; echo bar) > baz & (sleep 1 ; cp fnord baz)
$ cat baz
fnorbar
;; On Emacs 23, this returns "Received 5001 bytes, should be 5001"
;; On Emacs 24.3.50, this returns "Received 4096 bytes, should be 5001"
(let* ((buffer (generate-new-buffer "*bug-test*"))
(proc (start-process "cat" buffer "cat")))
(with-current-buffer buffer
(erase-buffer)
(process-send-string proc (concat (make-string 5000 ?a) "\n"))
(while (not (progn
(goto-char (point-min))
(re-search-forward "\n" nil t)))
>>> import dis
>>> def add(a, b):
... return a + b
...
>>> dis.dis(add)
2 0 LOAD_FAST 0 (a)
3 LOAD_FAST 1 (b)
6 BINARY_ADD
7 RETURN_VALUE
(cond
(switch-window-prev
(setq switch-window-prev nil)
(previous-multiframe-window))
(t
(setq switch-window-prev t)
(next-multiframe-window)))
(defun window-bottom--is-past-buffer/lines ()
"Return a true value iff we scrolled past the buffer end."
(save-excursion
(goto-char (window-start))
(let ((lines 0)
(max-lines (window-height)))
(while (and (< lines max-lines)
(re-search-forward "[\n\C-m]" nil t))
(setq lines (+ 1 lines)))
(goto-char (point-max))
(defun plist-merge (a b)
(let ((result a))
(while b
(let ((k (car b))
(v (cadr b))
(rest (cddr b)))
(when (not (plist-get result k))
(setq result (append (list k v)
result)))
(setq b rest)))
(let loop ((plist the-plist))
(when (not (null? plist))
;; Here you do something that might or might not result in
;; something. We do not know, "..." could be anything.
(let ((key (car plist))
(val (cadr plist)))
...)
;; But here, you ignore the result, and just loop over the list.
(loop (cddr plist))))
(defun friedbob/backtab ()
"Kill up to `tab-width' spaces backwards."
(interactive)
(let ((n tab-width))
(while (> n 0)
(when (looking-back "\\s-")
(delete-char -1))
(setq n (1- n)))))