Monthly Archives: January 2015

Using emmet-mode in Emacs for HTML Editing

When in Windows, I have a bad habit of using Sublime Text 2 instead of Emacs — I know, I’m ashamed of myself. It has some very useful features that I’ve really gotten used to using. Among them is the HTML dom shorthand… an example, if I type:

hr.margin-none <TAB>

Then it automatically expands to:

<hr class="margin-none"></hr>

Very useful when typing the code out yourself and not using a GUI editor… so I wanted to see if this functionality was available in Emacs. The good folks over at StackOverflow were quick to answer my question, and now I’ve been introduced to emmet-mode. It works the same, except by default the key binding to cause the expand is C-j, instead of TAB in Sublime Text. I think making a local emmet-mode keybinding may take care of this, but I’ve not played around with it enough yet. You can get emmet-mode from marmalade or MELPA repositories.

 

Mounting LVM Volumes in Linux with Rescue/Live Disk

So lately I’ve been playing around with a single remote-mounted nfs home directory at home. I’ve used it at work for years, and it’s great having all of my stuff in one location no matter what system I’m logged into. The setup was quite straightforward, except I’m still troubleshooting why my system hangs shortly after I login. I even made sure to include the _netdev option in my fstab so that it wouldn’t get mounted until after the network/nfs services are started, but it’s still causing me an issue. Anyway, the temporary solution is one I use rarely enough that I wanted to document it here… mounting an LVM volume manually when LVM isn’t already started. This is because I booted from the Fedora 20 Live disk in order to edit my fstab so I could login.

Here’s what I had to do in order to get my root partition to mount:

vgscan         # you may have to run 'lvm vgscan', but the former worked for me
vgchange -ay   # again you may have to run 'lvm vgchange -ay'
mount /dev/rootdg/root /mnt   # your volume group and volume name may differ
vi /mnt/etc/fstab

Be sure to get the one in /mnt, not in /etc, because that’s  your Live Install fstab and it won’t persist nor have anything useful in it.

Once I’ve made my changes, I reboot. Viola, you’re saved!

Using VI Inside of Emacs with ansi-term

As I’m still in the transition to use Emacs more often, I find myself often wanting to do a quick-and-dirty edit in vi. Rather than open another terminal (which can be disruptive if I have a tiling window manager with a particular layout configured), I like to have an ansi-term shell open in another Emacs frame. I usually use C-x 2 to split the window vertically, then C-x o to switch to the second frame, and M-x ansi-term RET to start an ansi-term shell. It will prompt for the shell to use, defaulting to the current shell of that user, in my case it will be /bin/bash or /bin/zsh depending on which system I’m using.

One great thing about ansi-term is that aside from the control/meta keystrokes, it’s a true ANSI-compliant terminal shell. You can still use C-x C-f and other key sequences (which in that case will open a new file in a new buffer) but you can also use C-c to cancel the current command, interrupt the running process, etc., except you have to hit it twice to tell ansi-term that you wanted to pass that control-c into the shell, not for Emacs itself to process. One of the only differences I’ve found, and it suits my needs just fine.

Now, for the quick-and-dirty edits — using vi or vim works perfectly fine within the Emacs ansi-term. The only issue I’ve found is that if I’m inside the file long enough, I often forget that I’m in VI and I will try to save the file with C-x C-s, and VI doesn’t really like that very much. Another thing of note — often I’m sudo’ed to root in the ansi-term window for various reasons, and vi’ing a file then will edit it as root, but using C-x C-f to open the file inside a new Emacs buffer will open it as the user ID that initiated the Emacs client (as I run Emacs in daemon mode almost exclusively), so I won’t have permissions to edit system files natively. I could use tramp/sudo, but sometimes it’s just faster to edit with VI. I’ve found this handy for multiple occasions so far.

One thing to note — using VI inside another Emacs shell (shell, term, iterm) can have strange results when attempting to save, enter/exit command mode, etc., so use at your own risk!