Mu2e Home
Emacs Hints
Search
Mu2e@Work

  1. emacs and xemacs?
  2. What to do about Tab Characters?
  3. Viewing the Geometry Files with C++ Mode
  4. Viewing the FHiCL Files with art-fhicl Mode
  5. Forcing a newlne at the end of file


emacs and xemacs

On detsim and mu2egvpm* the editor emacs is available as part of the SLF5 distribution. As of January 2012, the version is GNU Emacs 21.4.1. On mu2egpvm* the xemacs editor is also available but not as part of SLF5; it is available as a UPS product. As of January 2012, the most recent version is 20.4. To setup this version, make sure that you have enabled the old-style UPS/UPD, then

setup xemacs v20_4
At present there is no version of xemacs installed on detsim but we can ask for it.

What to do about Tab Characters?

I would like to propose the following as a standard practice for Mu2e:

Please configure your editor(s) so that they do not write tab characters to source code files. Please do configure your editor so that, when you hit the tab key, it inserts the appropriate number of spaces to achieve the desired formatting.

The short answer is to add the followieng line to the end of your ~/.emacs file

(setq-default indent-tabs-mode nil)
If you are using xemacs, add the same line to your ~/.xemacs/init.el file.

For more details see the discussion on configuring editors not to use tabs.

Viewing the Geometry Files with C++ Mode

If you use an editor with syntax highlighting, it is helpful to view the the Mu2e geometry files and the Mu2e generator configuration files using C++ mode with syntax highlighting. This is helpful because the language used in these files has a C++-like syntax. For the time being, these files have a file type of .txt which complicates the job of automatically selecting C++-mode when opening the file. In the future we may change the file type from .txt in order to make it easier to choose appropriate syntax highlighting.

Even without this change, if you use the emacs editor, you can automatically enable c++-mode in a geometry or generator configuration file by adding the following comments at the end of the file:

// Local Variables:
// mode:c++
// End:
The capitalization and the : are important. If you have syntax highlighting automatically enabled for c++ mode then these files will be viewed with syntax highlighting. I will add comments like this to the end of most of the geometry and generator configuration files.

This technique is described in the emacs manual under the section that discusses File Variables.

Viewing the FHiCL files with art-fhicl Mode

An emacs mode for editing FHiCL files has been developed and is accessible directly through the Fermilab common UPS products area. For those who use the mu2egpvm*.fnal.gov or detsim.fnal.gov machines, the mode can be enabled by logging on to the machine, and then typing the following on the command line:

ups configure art_fhicl_mode
This will add the following lines to the end of your ~/.emacs file:
(load (shell-command-to-string (concat ". " (getenv "SETUPS_DIR") "/setups.sh; setup art_fhicl_mode; printf $ART_FHICL_MODE_DIR/art-fhicl-mode.el")) nil t t)
(add-to-list 'auto-mode-alist '("\\.fcl$" . art-fhicl-mode))
In order to ensure that syntax highlighting is enabled, the following line must also be present in your ~/.emacs file:
; enable color syntax highlighting everywhere
(global-font-lock-mode t)

Alternatively, you can download the art-fhicl-mode.el file from Github. Create the directory ~/share/emacs/site-lisp/ and move the art-fhicl-mode.el source code there.Add the following code to your ~/.emacs file:

; extend the search path
(add-to-list 'load-path "~/share/emacs/site-lisp")
; enable color syntax highlighting everywhere
(global-font-lock-mode t)
; load art-fhicl-mode for fcl highlighting, etc.
(load "art-fhicl-mode.el" nil t t)
; associate .fcl files with art-fhicl-mode
(add-to-list 'auto-mode-alist '("\\.fcl$" . art-fhicl-mode))
Note that FHiCL is nearly identical structurally to YAML, and it is possible to use YAML mode to syntax highlight FHiCL, obtained here. The dedicated art-fhicl mode is likely to be more helpful, however.

Forcing a newline at the end of File

In all cases that are relevant for Mu2e, a properly formatted text file must end in a newline character ( this is the character created by pressing the enter key on your keyboard ). This is true for source code files, FHiCL files, the geometry file and so on. It is also true for the crontab file used to auto-renew your grid proxy.

Some of the applications that digest these files, such as the g++ compiler, are forgiving about a missing terminal newline. Other applications are not. In particular:

  1. In the mu2egrid scripts, the option --prestage-spec=file.list says that the file named "file.list" contains a list of files to be pre-staged to the worker node. If this file does not end in a newline, the last line in the file will be ignored and that file will not be pre-staged.
  2. cron will ignore the last line in a crontab file if terminal newline is missing.

If you use emacs, you tell emacs to check for the terminal newline and to add one if it is missing. There are several ways to do this. In your .emacs file you can add the line:

(setq-default require-final-newline t)
This will force a newline whenever you save a file. Alternatively, you can add the following to your .emacs file
(setq-default require-final-newline 'visit-save)
When this identifies a missing newline, it will prompt you for whether or not it should add a newline.


Fermilab at Work ]  [ Mu2e Home ]  [ Mu2e @ Work ]  [ Mu2e DocDB ]  [ Mu2e Search ]

For web related questions: Mu2eWebMaster@fnal.gov.
For content related questions: kutschke@fnal.gov
This file last modified Thursday, 15-Nov-2018 11:38:57 CST
Security, Privacy, Legal Fermi National Accelerator Laboratory