Skip to content

Instantly share code, notes, and snippets.

;; This is from simple.el of Bzr-110657. Looks normal? Please take a
;; look at the second if statement. What's the condition, the
;; consequent, and the alternative? Once you thought about that, count
;; parens. (Or paste it over to another buffer and actually let Emacs
;; indent it.)
(defun count-lines (start end)
"Return number of lines between START and END.
This is usually the number of newlines between them,
but can be one more if START is not equal to END
(defun fc/comint-send-as-input (buffer input)
"Send INPUT to the comint process in BUFFER."
(with-current-buffer buffer
(let* ((process (get-buffer-process buffer))
(beg (process-mark process))
(end (point-max))
(old (buffer-substring beg end)))
(delete-region beg end)
(goto-char beg)
(insert input)
(defun test-filter (process string)
(with-current-buffer (process-buffer process)
(insert "Filter: " string)))
(defun test-sentinel (process event)
(with-current-buffer (process-buffer process)
(insert "Sentinel: " event)))
(let ((buf (get-buffer-create "*Test*")))
(make-network-process :name "*Test*"
:buffer buf
@jorgenschaefer
jorgenschaefer / better-electric-pair.el
Created November 17, 2012 15:42
Better electric-pair-mode
(defun electric-pair-post-self-insert-function ()
(let* ((syntax (and (eq (char-before) last-command-event) ; Sanity check.
(electric-pair-syntax last-command-event)))
;; FIXME: when inserting the closer, we should maybe use
;; self-insert-command, although it may prove tricky running
;; post-self-insert-hook recursively, and we wouldn't want to trigger
;; blink-matching-open.
(closer (if (eq syntax ?\()
(cdr (or (assq last-command-event electric-pair-pairs)
(aref (syntax-table) last-command-event)))
(defun ngz/copy-buffer (oldbuf new-name)
"Create a new buffer named NEW-NAME as a copy of OLDBUF.
Will copy the contents and all buffer-local variables.
Returns the newly-created buffer"
(let ((newbuf (get-buffer-create new-name)))
(with-current-buffer oldbuf
(copy-to-buffer newbuf (point-min) (point-max)))
(with-current-buffer newbuf
(defun ngz/copy-buffer (oldbuf new-name)
"Create a new buffer named NEW-NAME as a copy of OLDBUF.
Will copy the contents and all buffer-local variables.
Returns the newly-created buffer"
(let ((newbuf (get-buffer-create new-name)))
(with-current-buffer oldbuf
(copy-to-buffer newbuf (point-min) (point-max)))
(with-current-buffer newbuf
(defun ngz/copy-buffer (oldbuf new-name)
"Create a new buffer named NEW-NAME as a copy of OLDBUF.
Will copy the contents and all buffer-local variables.
Returns the newly-created buffer"
(let ((newbuf (get-buffer-create new-name)))
(with-current-buffer oldbuf
(copy-to-buffer newbuf (point-min) (point-max)))
(with-current-buffer newbuf
(defun ngz/copy-buffer (oldbuf new-name)
"Create a new buffer named NEW-NAME as a copy of OLDBUF.
Will copy the contents and all buffer-local variables.
Returns the newly-created buffer"
(let ((newbuf (get-buffer-create new-name)))
(with-current-buffer oldbuf
(copy-to-buffer newbuf (point-min) (point-max)))
(with-current-buffer newbuf
@jorgenschaefer
jorgenschaefer / gist:4141853
Created November 24, 2012 23:53
copy-buffer
(defun ngz/copy-buffer (oldbuf new-name)
"Create a new buffer named NEW-NAME as a copy of OLDBUF.
Will copy the contents and all buffer-local variables.
Returns the newly-created buffer"
(let ((newbuf (get-buffer-create new-name)))
(with-current-buffer oldbuf
(copy-to-buffer newbuf (point-min) (point-max)))
(with-current-buffer newbuf
;; Here is a complete example of the settings you would use for
;; iPython 0.11:
;; (setq
;; python-shell-interpreter "ipython"
;; python-shell-interpreter-args ""
;; python-shell-prompt-regexp "In \\[[0-9]+\\]: "
;; python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
;; python-shell-completion-setup-code
;; "from IPython.core.completerlib import module_completion"