UNIX – Copying and Pasting With EMACS and Spawning New Windows

by on August 21, 2010

in consumer

Using EMACS

&

SPAWNING New Windows

-

Using EMACS in UNIXI use EMACS often and I find that I often am copying lines of text into files I’ve opened with emacs. It’s what I do. I have a huge KSH script, I want to add a section, so I test the new add-in by itself. Then when I am satisfied, I copy & paste from my test script/executable into my target code. But if you’re somewhat new to this arena, especially with using UNIX, you’ll probably wonder how the heck I’m opening an emacs sessions and still copy and paste into it?

One of my favorite methods of using EMACS is by adding a child session spawn signal to the end of my command line. (That’s my own name for it) It looks like this:

emacs filename &

The ‘&’ opens a new window and it leaves the original window available for use, just as always.

When I first started using the ‘&’ symbol, I typed it all the time and then found myself getting tired of typing it. (I’m what I jokingly refer to as lazy, and end up writing scripts and aliases for my work.) When I decided to add an alias to my CSH environment, this is one of my example lines from my ‘.cshrc’ file for using emacs and automatically adding the child process spawning symbol to the end of my command:

emacs emacs -geometry 100×35 -bg white -fg blue !* &

Aside from the geometry bits, my base alias is ‘emacs emacs !* &’.

The ‘!*’ is an open parameter like ‘$1′ that requires filling in, ie, with your filename of choice to edit. The ‘&’ is in place to effect the new window opening. Hence, with the new alias, and once I source my ‘.cshrc’ file, all I have to type is the following:

emacs filename

This opens the editing session in a new window and leaves your original window open to do with what you please. And yes, you can ‘edit / create’ new windows as often as you need.

Another way to tackle editing 2 files at once is by doing the following command:

emacs file1 file2

This opens a split window with file1 in the top window and file2 in the bottom window. You can then click in the desired window and do what you want or need to.

On That Geometry Switch for Emacs

In case you were wondering about the first example I presented:

emacs emacs -geometry 100×35 -bg white -fg blue !* &

The ‘-geometry 100×35 -bg white -fg blue’ part is saying give me a 100×35 sized window, make my background (bg) white and my foreground, ie the letters (fg) blue. There are many colors for both settings I have many aliases for my emacs settings just to keep it interesting. OR It makes it easier to identify what I’m editing when I use various colors to represent different things, like file being read versus file being edited. Or text file versus an executable file.

Of course, your performance may vary from UNIX to UNIX session. I use 3 different flavors of unix and I’ve found these basic aliases to work consistently for me across all the platforms.

Hope this helps someone just starting out in the the world of UNIX and using EMACS!

Related posts

Leave a Comment

Previous post:

Next post: