Skip to content

Instantly share code, notes, and snippets.

View howardabrams's full-sized avatar

Howard Abrams howardabrams

View GitHub Profile
#+TITLE: ${1:`(->> (buffer-file-name)
(file-name-base)
(s-split-words)
(--map (s-capitalize it))
(s-join " "))`}
#+AUTHOR: `user-full-name`
#+EMAIL: `user-mail-address`
#+DATE: `(format-time-string "%Y-%m-%d")`

Tangling an org-mode file when the :tangle parameter is set to yes, writes each block into a single file based on a language and the name of the org file. In this case, my file is /tmp/example.org, so all Ruby blocks will be written into a single file, /tmp/example.rb. But this can be change as shown below.

Section One

For this example, the :tangle parameter is simply yes, which grabs the defaults:

echo In section one
@howardabrams
howardabrams / .profile.sh
Last active December 31, 2019 03:31
Bulk of my server-side profile that when I first log into the system, it starts up Emacs as a daemon and a `tmux` session. From then on, I just attach to that `tmux,` and use `emacsclient` to edit files... especially with a `split-window`.
alias e='emacsclient -q -a emacs'
EDITOR=emacsclient
function e {
tmux new-window -a -n "emacs" "$EDITOR $@"
}
function ee {
tmux split-window "$EDITOR $@"
#+NAME: foobar-contents
#+begin_src emacs-lisp
(with-temp-buffer
(insert-file "/tmp/foobar")
(buffer-string))
#+end_src
#+RESULTS: foobar-contents
: Curabitur lacinia pulvinar nibh. Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus.
: Donec at pede. Curabitur lacinia pulvinar nibh. Nam euismod tellus id erat.
(defun remote-shell-fav-hosts-get ()
"My hook to the remote-shell processes in order to connect to
my OpenStack controller, and create a hashtable of host names as
the keys, and IP addresses as the values."
(interactive)
;; Run nova list command remotely on this host system, and put the
;; results in a temp buffer:
(let* ((undercloud-controller "10.98.1.145")
(default-directory (format "/ssh:%s:" undercloud-controller))
@howardabrams
howardabrams / increment-number.el
Last active December 10, 2016 11:36
A simple approach to easily incrementing (or decrementing) the next number in an Emacs buffer. This seems to be helpful when editing odd XML data files.
(defun increment-decrement (amount)
(let* ((for-number "[0-9][0-9]*")
(end (re-search-forward for-number))
(start (match-beginning 0))
(str (buffer-substring start end))
(num (+ amount (string-to-number str))))
(delete-region start end)
(insert (number-to-string num))
(goto-char start)))
@howardabrams
howardabrams / little-eshell.el
Last active December 10, 2016 11:36
A function for creating small, temporary eshell buffers that will be "somewhat associated" with a particular buffer (since it is named after the directory that file is in).
(defun eshell-here ()
"Opens up a new shell in the directory associated with the current buffer's file."
(interactive)
(let* ((parent (if (buffer-file-name)
(file-name-directory (buffer-file-name))
default-directory))
(height (/ (window-total-height) 3))
(name (car (last (split-string parent "/" t)))))
(split-window-vertically (- height))
(other-window 1)
@howardabrams
howardabrams / .emacs
Last active December 10, 2016 11:35
In my Emacs initialization, I run through a few functions that automatically set up my windows and environment. This `setup-windows` function is unique for each machine that I work on, but I bind it to <F6>, so that I can easily start this. Why yes, if I run this function, I rebind it.
(defun setup-windows ()
"Setup my entire Emacs environment. Function is often called when I first start it up."
(interactive)
(frame-fullscreen)
(split-window-horizontally 168) ;; On this machine, I know how big
(split-window-horizontally 84) ;; my monitor is, so ...
(other-window 2)
(split-window-vertically)
(circe-connect-all) ;; Connect to all my IRC channels
(twit) ;; Start twitter in this window
@howardabrams
howardabrams / surround.el
Last active December 10, 2016 11:35
Now that we can easily make a region based on "syntactic components" using the `expand-region` command, wrapping a logical block of text with a beginning and ending string really makes sense.
(defun surround (start end txt)
"Wraps the specified region (or the current 'symbol / word'
with some textual markers that this function requests from the
user. Opening-type text, like parens and angle-brackets will
insert the matching closing symbol.
This function also supports some org-mode wrappers:
- `#s` wraps the region in a source code block
- `#e` wraps it in an example block
@howardabrams
howardabrams / surround-v2.el
Last active December 10, 2016 11:35
Now that we can easily make a region based on "syntactic components" using the `expand-region` command, wrapping a logical block of text with a beginning and ending string really makes sense. This "version" is more Emacs-y in that it `lets` all the variables, and then `setq` them to their proper values. While I'm not pedantic, I don't like such …
(defun surround (start end txt)
"Wraps the specified region (or the current 'symbol / word'
with some textual markers that this function requests from the
user. Opening-type text, like parens and angle-brackets will
insert the matching closing symbol.
This function also supports some org-mode wrappers:
- `#s` wraps the region in a source code block
- `#e` wraps it in an example block