Archive for the 'Software' Category

3Monkeys on Emacs: Part 1 – Introduction

Wednesday, July 4th, 2007

Introduction

I have been an Emacs user for the better part of 17 years or so. Even so, there are quite a few things I’ve learned and forgotten along the way and perhaps even more that I never learned. I am writing the series of articles to not only provide a tutorial for the beginning Emacs user, but to also dig in and uncover features that I haven’t used for some time and features I never knew about. For the time being, I will be discussing just Emacs and not XEmacs, if it becomes necessary or requested to cover XEmacs, I will consider it at that time.

Vi – Well any time you mention Emacs, there is inevitably a Vi/Vim/GVim user in the room, and just inevitably a Holy War between the two breaks out. I really do not want to start a Holy War here, therefore, I am inviting one or more Vi advocates to step up and be a guest author and contribute similar articles from a Vi perspective. If you are willing to do this please contact me.

Some Fundamentals

In any editor there are a few fundamental operations you must be able to perform, create a new file, edit an existing file, and save a file. Emacs provides several ways to do these, the most common being command keystrokes within Emacs itself, other methods are issuing the verbose command or in an XWindows session selecting from a menu.

  • Creating or Opening a File
    More often referred to as visiting a file or finding a file, can be accomplished by simply specifying one or more filenames on the command prompt when starting Emacs.
    For example:

    	% emacs foo.txt bar.csv

    This command will start emacs and open both foo.txt and bar.csv into editing buffers. If either file does not exist on disk, emacs will still create a new buffer for the specified file. It is important to realize the all editing in emacs is done in buffers and not on files directly. To have changes to a buffer reflected in the file on disk, you must save the buffer.

    Perhaps the most common way of visiting (opening) a file, is to use the keystroke command sequence C-x C-f. This is a two-key or extended command. The C- indicates that you must hold down the Control (Ctrl) key then press the following key, in the case of C-x that would be x. Many keystroke commands are of the extended command type and begin with C-x. When this command is executed you are prompted for a filename in the echo area, a small usually one line area at the bottom of the Emacs screen. Simply enter the files name and press return to visit the file and load a buffer with its contents. Emacs supports tab completion, so as you type the name of the file you can press tab to either complete unique portions of the filename, or if there are no unique portions Emacs will open a completions buffer listing the legal possibilities. Again if the file you specify does not exist a new buffer associated with that filename will be created.

    You can also choose to verbosely run the command. To run a verbose command, start by entering command mode by issuing the keystroke command M-x, where M-x indicates to press and hold down the Meta (Esc) key and then press x. This will allow you to execute Emacs commands directly from the echo area. The command for opening a file is find-file, simply type this in the echo area using tab completion if desired and press return. This will provide the same prompt in the echo area as the Cx C-f keystroke command described above.

    Finally, if your system supports it, you can select the visit file menu item from the Emacs menu. This operation is strongly tied to the type of system you happen to be running on so I will not cover menu items in detail.

  • Saving a File
    Saving a file is generally performed with the keystroke command, C-x C-s. This will save the current buffer to disk if the buffer was associated with a file to begin with. Certain buffers are not associated with on disk files however, if you save a buffer of this type, Emacs will prompt you for a file name in the echo area. Such buffers could be scratch or shell buffers. The verbose command for saving a buffer is save-buffer. If you wish to save the buffer to file of a different name, use the C-x C-w keystroke command. Emacs will prompt you for the new name in the echo area. The verbose command for saving a buffer to a new filename is write-file.

The next article in this series will cover navigating through a buffer.

Next in this series: Part 2 – Basic Navigation and Editing

Until next time…

-3Monkeys

Popularity: 14% [?]

  • DZone
  • StumbleUpon
  • Technorati
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • NewsVine
  • SphereIt
  • e-mail
  • Facebook
  • Google Bookmarks
  • Live
  • Propeller

For Alex and Mike on the Passing of Erik’s Linkblog

Thursday, June 21st, 2007

A few bloggers are lamenting about the passing of Erik’s Linkblog. So Alex and Mike I give you a some reprieve and offer this bit of code you can insert into your own blog. While it is not Erik’s link blog, at least you can get your fix of daily Java articles.

<script language=”JavaScript” src=”http://www.dzone.com/dzonelive/3monkeys/frontpage/java/62″ type=”text/javascript”></script>

You can also customize this script at http://www.dzone.com/add-dzone.jsp

You may also notice that Erik included a similar script in his page that displays all of the current stories from DZone.

Java Links

Popularity: 11% [?]

  • DZone
  • StumbleUpon
  • Technorati
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • NewsVine
  • SphereIt
  • e-mail
  • Facebook
  • Google Bookmarks
  • Live
  • Propeller

OpenOffice .odt Opened Up – Part 3a: Styles/font-face-decls

Wednesday, April 4th, 2007

Overview

In my last article, OpenOffice .odt Opened Up – Part 2: Meta and Settings, I discussed two of the four top level subdocument elements, office:document-meta and office:document-settings. In this article, I will be taking a closer look at the office:document-styles element, in particular the office:font-face-decls sub-element. As before, my test cases where produced with the following software:

  • SuSE Linux 10.1
  • OpenOffice 2.0.2.7.1
  • zip 2.31 (March 8th 2005)

The Relax-NG schema language is used to define elements of the specification. The original source document can be downloaded here oo_part1.odt, and in particular the subdocument under observation can be downloaded here styles.xml.

The office:document-styles element

The office:document-styles root element contains all font face declarations, named styles, automatic styles and master styles need for the document.

office:document-styles schema

<define name="office-document-styles">
  <element name="office:document-styles">
    <ref name="office-document-common-attrs" />
    <ref name="office-font-face-decls" />
    <ref name="office-styles" />
    <ref name="office-automatic-styles" />
    <ref name="office-master-styles" />
  </element>
</define>

Next let us explore the office:font-face-decls sub-element.

The office:font-face-decls element

This element is actually duplicated in the top-level office:document-content element. A few simple test indicate that, if differences exist in the two sub-elements, complete element omissions in one are populated by the other, and where two elements differ in content the definition in office:document-styles takes precedence, though this behavior is not defined explicately in the specification.

The office:font-face-decls element consist of style:font-face elements. If you remember, we generated our test document by selecting text from a pdf and pasting that text into an .odt. This generated such style:font-face elements as follows:

<style:font-face style:name="EIDQUI+CMSLTT10"
                 svg:font-family="EIDQUI+CMSLTT10"/>

<style:font-face style:name="FFWLFJ+CMR10"
                 svg:font-family="FFWLFJ+CMR10"/>

<style:font-face style:name="GRVNVC+CMTT9"
                 svg:font-family="GRVNVC+CMTT9"/>

<style:font-face style:name="HJCZVV+CMTT8"
                 svg:font-family="HJCZVV+CMTT8"/>

<style:font-face style:name="Lucidasans1"
                 svg:font-family="Lucidasans"/>

With the exception of the last element, this looks pretty ugly. The following is a sample of style:font-face elements taken from a newly created document.

<style:font-face style:name="HG Mincho Light J"
                 svg:font-family="’HG Mincho Light J’"
                 style:font-pitch="variable"/>

<style:font-face style:name="Lucidasans"
                 svg:font-family="Lucidasans"
                 style:font-pitch="variable"/>

<style:font-face style:name="Thorndale AMT"
                 svg:font-family="’Thorndale AMT’"
                 style:font-family-generic="roman"
                 style:font-pitch="variable"/>

<style:font-face style:name="Albany AMT"
                 svg:font-family="’Albany AMT’"
                 style:font-family-generic="swiss" />

The reason for this is that OpenDocument font face declarations directly correspond to the @font-face font description of CSS2 and the <font-face> element of SVG, but have two extensions.

  1. OpenDocument font face declarations optionally may have an unique name. This name can be used inside styles as the value of the style:font-name attribute to immediately select a font face declaration. If a font face declaration is referenced this way, the steps described in CSS2 font matching algorithms for selecting a font declaration based on the font-family, font-style, font-variant, font-weight and font-size descriptors will not take place, but the referenced font face declaration is used directly.
  2. Some additional font descriptor attributes may exist.

Which basically means svg:font-family="EIDQUI+CMSLTT10" uses the SVG font matching algorithm and not the named font. SVG is beyond the scope of this article. Reference material for SVG font declarations can be found here.

Back to the bigger picture. The benefit we can observe from this, is that a predefined set of fonts can be applied to an .odt. By doing this we can ensure that documents contain a consistent set of fonts and eliminate potential redundancy or functional overlap. Care must be taken that if a style:font-face is replaced, that all style:font-name, style:font-name-complex and style:font-name-asian attributes are examined and replaced as well. While potential size gains are arguably minimal, gains in consistent look and output are immeasurable.

One option Open Office gives the user to tackle this issue is the font replacement option. Simply choose Tools -> Options then OpenOffice.org -> Fonts. You should see a dialog similar to the following:

Font Replacement Dialog

Click for full size image

The Open Office user can simply select which fonts to replace with which fonts on an Always or Screen only case. Though this is not always a complete solution. Amore complete solution will be provided in the final installment of OpenOffice .odt Opened Up – Part 3: Styles. I will provide an application that will indeed optimize all of the aspects of the office:document-style elements. Up next is the office:styles element.

Until next time,

-3monkeys

Popularity: 18% [?]

  • DZone
  • StumbleUpon
  • Technorati
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • NewsVine
  • SphereIt
  • e-mail
  • Facebook
  • Google Bookmarks
  • Live
  • Propeller