Emacs / Xemacs tips

 

emacs

emacs-version

Legacy code in .emacs used the following to distinguish GNU emacs from

XEmacs...

(string-match "GNU" emacs-version)

 

This no longer works in later versions. e.g. emacs-version "21.4.2"

Use this instead:-

(cond

 ((string-match "XEmacs" emacs-version)

 (expression)))

or

(unless (string-match "XEmacs" emacs-version)

 (expression))

 

xemacs

installing local xemacs on linux

 

configure --prefix=/home/bak

 

may get error "cannot find -ltermcap"

requires libncurses5-dev package (requires root access to install)

sudo apt-get install libncurses5-dev

 

make install

 

may get some of the following  errors if X11 packages are missing:-

"X11/bitmaps/gray: No such file or directory"

sudo apt-get install xbitmaps

 

"X11/Xaw/Form.h: No such file or directory"

sudo apt-get install libxaw7-dev

 

makeinfo executable missing

sudo apt-get install texinfo

 

~/.xemacs/init.el

 

Used instead of ~/.emacs

~/.emacs is still used by GNU emacs

 

packages

 

old packages can be found here:-

http://ftp.us.xemacs.org/ftp/pub/xemacs/Attic/packages/oldpkg/

 

system wide packages are installed here:-

/usr/local/lib/xemacs/xemacs-packages

 

To install a package for private use (no root privilege),

place the tar.gz file into

~/.xemacs/xemacs-packages

gunzip -c foo.tar.gz | tar -xvf -

or

gunzip foo.tar.gz

tar -xvf foo.tar

 

Note that original package directory was named ~/.xemacs/packages

In legacy installations where this is still used, add a link to allow

backward compatability:-

ln -s ~/.xemacs/packages ~/.xemacs/xemacs-packages

 

line endings

 

To auto detect dos/unix line endings need to load crypt.el from os-utils package.

(require 'crypt)

 

svn support

 

Download psvn.el (Not a standard xemacs package)

http://www.xsteve.at/prg/vc_svn/

 

place in ~/.xemacs/xemacs-packages/lisp/psvn

 

add to init.el:-

(require 'psvn)

 

speedbar

 

speedbspec.el is no longer used in the later versions of speedbar.

imenu support package is required.

 

 

ftp problems

 

When attempting to retrieve packages or update the package index,

may encounter an error message

500 AUTH not understood

To fix...

M-x customize-variable

efs-ftp-program-args

Add -u

and save for future sessions.

 

 

function key bindings

 

For some PCs & Laptops there may be problems with shift-function keys

and control-function key bindings with xemacs when using Xfree86.

 

Use xmodmap to obtain a list of key mappings...

 

xmodmap -pke

 

This may contain something like this for the fn keys:-

 

keycode  67 = F1  XF86_Switch_VT_1

keycode  68 = F2  XF86_Switch_VT_2

keycode  69 = F3  XF86_Switch_VT_3

keycode  70 = F4  XF86_Switch_VT_4

keycode  71 = F5  XF86_Switch_VT_5

keycode  72 = F6  XF86_Switch_VT_6

keycode  73 = F7  XF86_Switch_VT_7

keycode  74 = F8  XF86_Switch_VT_8

keycode  75 = F9  XF86_Switch_VT_9

keycode  76 = F10 XF86_Switch_VT_10

 

To fix the problem for shift-function keys, capture the output from

xmodmap into a file:-

 

xmodmap -pke > .Xmodmap

 

Edit the file and remove the XF86_Switch_VT_xx string on each line:-

keycode  67 = F1

keycode  68 = F2

keycode  69 = F3

keycode  70 = F4

keycode  71 = F5

keycode  72 = F6

keycode  73 = F7

keycode  74 = F8

keycode  75 = F9

keycode  76 = F10

 

Update xmodmap with the new file:-

xmodmap .xmodmap

Add the above line to .cshrc or .bashrc

 

Alternative solution for use in a network...

use "uname -n" to get network nodename

name the modmap file .xmodmap-<name>

(this is the naming convention xkeycaps uses - see below)

add to .cshrc:-

if (-e ~/.xmodmap-`uname -n`) xmodmap ~/.xmodmap-`uname -n`

 

A better way is to use xkeycaps to create a modmap file to match the keyboard.

The user selects the keyboard layout and country from a list.

It will create a suitable modmap file using the name .xmodmap-`uname -n`.

The reulting modmap may result in warnings when xemacs starts up.

These can be removed by removing the line that maps both the Meta and Alt keys

to Mod1...

add    Mod1    = Meta_L Meta_R Alt_L Alt_R

 

Note: If the above solution is used when accessing a remote machine using vnc

then there could be problems when accessing the same machine when running

a local X server (such as Cygwin on a PC) in conjunction with ssh (putty) and

X11 forwarding.

This is because the modmap may be completely different.

However when logged into the remote machine using ssh (putty)

uname -n will give the same .xmodmap filename.

Hence either create a different .xmodmap file or prevent xmodmap being run

at all in the .cshrc file.

VNCDESKTOP environment variable can be used to detect if VNC is in use.

e.g.

if (${?VNCDESKTOP}) then

  if (-e ~/.xmodmap-`uname -n`) xmodmap ~/.xmodmap-`uname -n`

endif

 

Note: To check keycodes generated when a key is pressed use xev.

 

The above steps may only fix shift-fn keys.

Some window managers such as kde intercept control-fn and

shift-control-fn keys for switching between virtual desktops.

For kde, this can be disabled using /usr/bin/kcontrol:-

Accessibility->Keyboard Shortcuts->Shortcut Sequences.

 

Note: xemacs key bindings use the following format (see xpcx.el):-

(global-set-key [(shift f8)] 'edt-search-forward)

GNU emacs uses a different format (see pcx.el):-

(global-set-key [S-f8] 'edt-search-forward)

 

Note: On a Microsoft keyboard, the 'meta' key used in

global-set-key is labelled 'alt' on the keyboard.

 

links:-

http://www.xemacs.org/Links/tutorials_2.html

 

searching for control characters

 

e.g. find blank lines:-

 

M-x isearch-forward<RET>

^Q^J^Q^J

 

changing buffer mode

 

examples:-

M-x c++-mode

M-x c-mode

M-x text-mode

 

c-offsets-alist

 

Association list of syntactic element symbols and indentation offsets.

As described below, each cons cell in this list has the form:

 

    (SYNTACTIC-SYMBOL . OFFSET)

 

When a line is indented, CC Mode first determines the syntactic

context of it by generating a list of symbols called syntactic

elements.  This list can contain more than one syntactic element and

the global variable `c-syntactic-context' contains the context list

for the line being indented.  Each element in this list is actually a

cons cell of the syntactic symbol and a buffer position.  This buffer

position is called the relative indent point for the line.  Some

syntactic symbols may not have a relative indent point associated with

them.

 

After the syntactic context list for a line is generated, CC Mode

calculates the absolute indentation for the line by looking at each

syntactic element in the list.  It compares the syntactic element

against the SYNTACTIC-SYMBOL's in `c-offsets-alist'.  When it finds a

match, it adds the OFFSET to the column of the relative indent point.

The sum of this calculation for each element in the syntactic list is

the absolute offset for line being indented.

 

If the syntactic element does not match any in the `c-offsets-alist',

the element is ignored.

 

If OFFSET is nil, the syntactic element is ignored in the offset

calculation.

 

If OFFSET is an integer, it's added to the relative indent.

 

If OFFSET is one of the symbols `+', `-', `++', `--', `*', or `/', a

positive or negative multiple of `c-basic-offset' is added; 1, -1, 2,

-2, 0.5, and -0.5, respectively.

 

If OFFSET is a vector, it's first element, which must be an integer,

is used as an absolute indentation column.  This overrides all

relative offsets.  If there are several syntactic elements which

evaluates to absolute indentation columns, the first one takes

precedence.  You can see in which order CC Mode combines the syntactic

elements in a certain context by using M-x c-show-syntactic-information on the line.

 

If OFFSET is a function, it's called with a single argument

containing the cons of the syntactic element symbol and the relative

indent point.  The return value from the function is then

reinterpreted as an OFFSET value.

 

If OFFSET is a list, it's recursively evaluated using the semantics

described above.  The first element of the list to return a non-nil

value succeeds.  If none of the elements returns a non-nil value, the

syntactic element is ignored.

 

`c-offsets-alist' is a style variable.  This means that the offsets on

this variable are normally taken from the style system in CC Mode

(see `c-default-style' and `c-style-alist').  However, any offsets

put explicitly on this list will override the style system when a CC

Mode buffer is initialized (there is a variable

`c-old-style-variable-behavior' that changes this, though).

 

Here is the current list of valid syntactic element symbols:

 

 string                 -- Inside multi-line string.

 c                      -- Inside a multi-line C style block comment.

 defun-open             -- Brace that opens a function definition.

 defun-close            -- Brace that closes a function definition.

 defun-block-intro      -- The first line in a top-level defun.

 class-open             -- Brace that opens a class definition.

 class-close            -- Brace that closes a class definition.

 inline-open            -- Brace that opens an in-class inline method.

 inline-close           -- Brace that closes an in-class inline method.

 func-decl-cont         -- The region between a function definition's

                           argument list and the function opening brace

                           (excluding K&R argument declarations).  In C, you

                           cannot put anything but whitespace and comments

                           between them; in C++ and Java, throws declarations

                           and other things can appear in this context.

 knr-argdecl-intro      -- First line of a K&R C argument declaration.

 knr-argdecl            -- Subsequent lines in a K&R C argument declaration.

 topmost-intro          -- The first line in a topmost construct definition.

 topmost-intro-cont     -- Topmost definition continuation lines.

 member-init-intro      -- First line in a member initialization list.

 member-init-cont       -- Subsequent member initialization list lines.

 inher-intro            -- First line of a multiple inheritance list.

 inher-cont             -- Subsequent multiple inheritance lines.

 block-open             -- Statement block open brace.

 block-close            -- Statement block close brace.

 brace-list-open        -- Open brace of an enum or static array list.

 brace-list-close       -- Close brace of an enum or static array list.

 brace-list-intro       -- First line in an enum or static array list.

 brace-list-entry       -- Subsequent lines in an enum or static array list.

 brace-entry-open       -- Subsequent lines in an enum or static array

                           list that start with an open brace.

 statement              -- A C (or like) statement.

 statement-cont         -- A continuation of a C (or like) statement.

 statement-block-intro  -- The first line in a new statement block.

 statement-case-intro   -- The first line in a case "block".

 statement-case-open    -- The first line in a case block starting with brace.

 substatement           -- The first line after an if/while/for/do/else.

 substatement-open      -- The brace that opens a substatement block.

 substatement-label     -- Labelled line after an if/while/for/do/else.

 case-label             -- A "case" or "default" label.

 access-label           -- C++ private/protected/public access label.

 label                  -- Any ordinary label.

 do-while-closure       -- The "while" that ends a do/while construct.

 else-clause            -- The "else" of an if/else construct.

 catch-clause           -- The "catch" or "finally" of a try/catch construct.

 comment-intro          -- A line containing only a comment introduction.

 arglist-intro          -- The first line in an argument list.

 arglist-cont           -- Subsequent argument list lines when no

                           arguments follow on the same line as the

                           arglist opening paren.

 arglist-cont-nonempty  -- Subsequent argument list lines when at

                           least one argument follows on the same

                           line as the arglist opening paren.

 arglist-close          -- The solo close paren of an argument list.

 stream-op              -- Lines continuing a stream operator construct.

 inclass                -- The construct is nested inside a class definition.

                           Used together with e.g. `topmost-intro'.

 cpp-macro              -- The start of a C preprocessor macro definition.

 cpp-macro-cont         -- Inside a multi-line C preprocessor macro definition.

 friend                 -- A C++ friend declaration.

 objc-method-intro      -- The first line of an Objective-C method definition.

 objc-method-args-cont  -- Lines continuing an Objective-C method definition.

 objc-method-call-cont  -- Lines continuing an Objective-C method call.

 extern-lang-open       -- Brace that opens an "extern" block.

 extern-lang-close      -- Brace that closes an "extern" block.

 inextern-lang          -- Analogous to the `inclass' syntactic symbol,

                           but used inside "extern" blocks.

 namespace-open, namespace-close, innamespace

                        -- Similar to the three `extern-lang' symbols, but for

                           C++ "namespace" blocks.

 module-open, module-close, inmodule

                        -- Similar to the three `extern-lang' symbols, but for

                           CORBA IDL "module" blocks.

 composition-open, composition-close, incomposition

                        -- Similar to the three `extern-lang' symbols, but for

                           CORBA CIDL "composition" blocks.

 template-args-cont     -- C++ template argument list continuations.

 inlambda               -- In the header or body of a lambda function.

 lambda-intro-cont      -- Continuation of the header of a lambda function.

 inexpr-statement       -- The statement is inside an expression.

 inexpr-class           -- The class is inside an expression.  Used e.g. for

                           Java anonymous classes.

 

auto select mode for file extension

 (setq auto-mode-alist

    (append '(("\\.h$"  . c++-mode)

              ("Makefile" . makefile-mode)

    ) auto-mode-alist)

)

 

~.xemacs/init.el

 

;--------------------------------------

; ~/.emacs or ~.xemacs/init.el for bak

;--------------------------------------

 

(set-frame-size (selected-frame) 80 50)

 

;; legacy Gosling emacs key bindings for old GNU emacs version 19

(cond

  ((= emacs-major-version 19)

    (load "gosmacs")

    (set-gosmacs-bindings)

  )

)

 

;; turn on line number display (Xemacs)

(cond

  ((string-match "XEmacs" emacs-version)

    (line-number-mode 1)

  )

)

 

;; configure speedbar (Xemacs)

(cond

  ((string-match "XEmacs" emacs-version)

    (custom-set-variables

      '(speedbar-update-flag nil) ; turn off speedbar auto update

      '(speedbar-tag-split-minimum-length 30)

      '(speedbar-tag-regroup-maximum-length 20)

      '(speedbar-frame-plist (quote (minibuffer nil width 35 border-width 0 internal-border-width 0 unsplittable t default-toolbar-visible-p nil has-modeline-p nil menubar-visible-p nil)))

      '(speedbar-use-imenu-flag t)

      '(speedbar-tag-hierarchy-method (quote (sort sort)))

    )

  )

)

 

;; load imenu support for speedbar (mode specific buffer indexes) (Xemacs)

(cond

  ((string-match "XEmacs" emacs-version)

    (load "~bak/emacs/lisp/imenu")

  )

)

 

;; add speedbar to Tools menu (Xemacs)

(cond

  ((string-match "XEmacs" emacs-version)

    (add-menu-button '("Tools")

      ["Speedbar" speedbar-frame-mode

      :style toggle

      :selected (and (boundp 'speedbar-frame)

      (frame-live-p speedbar-frame)

      (frame-visible-p speedbar-frame))]

      "--"

    )

  )

)

 

;; configure speedbar (GNU emacs)

(unless (string-match "XEmacs" emacs-version)

  (define-key-after (lookup-key global-map [menu-bar tools])

    [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])

)

 

;; configure html helper mode

(load "~bak/emacs/html/tempo.el")

(load "~bak/emacs/html/html-helper-mode.el")

;;(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)

(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))

(setq html-helper-do-write-file-hooks t)

(setq html-helper-build-new-buffer t)

(setq html-helper-address-string

 "<a href=\"/cgi-bin/getuserinfo/bak\">Brian Keen &lt;brian.keen@ffei.co.uk&gt;</a>")

 

; custom settings

;(setq term-setup-hook 'enable-arrow-keys)

(setq default-major-mode 'text-mode)

; disable extending file as we move down past end

(defun next-line (arg)

  (interactive "p")

    (forward-line arg)

  nil)

;(setq term-setup-hook 'edt-emulation-on)

(setq manual-formatted-dir-prefix "/usr/man/catman/u_man/man")

(setq manual-program "/usr/ucb/man")

(setq-default explicit-shell-file-name "/bin/csh")

 

;(setq term-file-prefix nil)

 

(setq inhibit-startup-message nil)

(setq-default transient-mark-mode t)

 

;(define-key global-map "\C-s" 're-search-forward)

;(define-key global-map "\C-r" 're-search-backward)

;(define-key function-map "29~" 'execute-extended-command)

 

 

; force c++ mode for .h files

(setq auto-mode-alist

    (append '(("\\.h$"  . c++-mode)

              ("Makefile" . makefile-mode)

    ) auto-mode-alist)

)

 

;(defun bc-mode-hook2 () "My custom c-mode setup"

;  (progn

;    (setq c-tab-always-indent nil) ;t-> always reindent line on tab

;;    (setq c-auto-newline t) ;t-> add newline before/after braces,colons,semi

;    (setq c-indent-level 2) ;indent of block from surrounding braces

;    (setq c-continued-statement-offset 0) ;indent of if/while body etc

;    (setq c-continued-brace-offset 0) ;add to c-c-s-o for opening brace

;    (setq c-brace-offset 0) ;extra indent for line starting with open brace

;    (setq c-brace-imaginary-offset 0); treat brace after text as this far over

;    (setq c-argdecl-indent 0) ; indent of function arg decls

;    (setq c-label-offset 2) ; extra indent for labels,cases,defaults

;  )

;)

 

(defun bc-mode (bc-offset) "My custom c++-mode and c-mode setup"

  (progn

;    (setq c-set-style "linux")

;    (setq c-default-style "linux")

    (setq c-basic-offset bc-offset) ; usually 2 or 4 as required

    (setq c-offsets-alist

     '(

        (topmost-intro . 0)         ; top level indent

        (substatement-open . 0)     ; extra indent before opening brace

        (substatement . +)          ; extra indent after if or else

        (statement-block-intro . +) ; extra indent on tab

;        (statement-cont . -)        ; extra indent on closing brace

        (statement-cont . 0)        ; extra indent on closing brace

        (defun-block-intro . +)     ; extra indent in function

        (inclass . +)               ; extra indent in class

        (case-label . +)            ; extra indent in case label

        (access-label . -)          ; extra indent in access label

        (statement-case-intro . +)  ; extra indent in case

        (member-init-intro . +)     ; extra indent for member init

        (label . +)                 ; extra indent for labels

        (innamespace . +)           ; extra indent for namespace

      )

    )

    (c-set-offset 'arglist-cont '(c-lineup-arglist-operators 0))

    (c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist-operators c-lineup-arglist))

    (c-set-offset 'arglist-close '(c-lineup-arglist-close-under-paren))

    (setq-default indent-tabs-mode nil) ;use spaces for indent rather than tabs+spaces

    (setq tab-width bc-offset) ;for existing files that do use tabs

  )

)

 

(defun bc-mode-hook () "My custom c-mode setup"

  (progn

    (bc-mode 2) ; set bc-offset param to 2 or 4 as required

  )

)

 

(defun bc++-mode-hook () "My custom c++-mode setup"

  (progn

    (bc-mode 4) ; set bc-offset to 2 or 4 as required

  )

)

 

(setq c-mode-hook 'bc-mode-hook)

(setq c++-mode-hook 'bc++-mode-hook)

 

 

;(setq c-argdecl-indent 0)

;(setq c-brace-offset 4)

;(setq c-indent-level 0)

;(setq c-continued-statement-offset 4)

;(setq inhibit-startup-message t)

 

;; configure gnus reader

(setq gnus-nntp-server "")

(setq gnus-nntp-service nil)

(setq gnus-local-domain "ffei.co.uk")

(setq gnus-local-organization "FFEI, Hemel Hempstead, UK")

(setq gnus-signature-file "~/.signature.gnus" )

(setq gnus-news-system 'Cnews )

(setq gnus-use-generic-from t)

(setq gnus-novice-user t)

(setq news-path "/usr/spool/news/")

(setq nnspool-active-file "/usr/lib/news/active")

(setq nnspool-history-file "/usr/lib/news/history")

(setq news-inews-program "/usr/lib/news/inews")

(setq gnus-use-generic-path t)

(setq gnus-show-threads nil)

 

(autoload 'gnus "gnus" "Read network news." t)

(autoload 'gnus-post-news "gnuspost"      "Post news." t)

 

;(setq compile-command "/usr/local/ngslocal/bin/rcs/make -k VIPER=1 ")

 

;(display-time)

 

(setq lpr-switches '("-Plj9text"))

 

;; auto-detect dos line endings

(cond

  ((string-match "XEmacs" emacs-version)

    (require 'crypt)

  )

;;  (t (require '~/.xemacs/packages/lisp/os-utils/crypt.el))

)

 

;; subversion support

;(load "~bak/emacs/lisp/psvn")

(require 'psvn)

 

(load "simple")

 

;; load key bindings and functions according to termtype

(setq termtype (getenv "TERM"))

 

(if (or (equal termtype "vt100")

        (equal termtype "vt220")

        (equal termtype "network"))

  (progn(load "~bak/emacs/lisp/brian"))

 

  (if (or (equal termtype "sun")

          (equal termtype "xterm")

          (equal termtype "sun-cmd")

          (equal termtype "dtterm"))

 

    (cond((string-match "XEmacs" emacs-version)

      (progn(load "~bak/emacs/lisp/xpcx")))

    )

  )

)

 

;; load key bindings & functions (GNU emacs)

(unless (string-match "XEmacs" emacs-version)

  (cond

    ((>= emacs-major-version 19)

      (progn(load "~bak/emacs/lisp/pcx")))

  )

)

 

 

(put 'downcase-region 'disabled nil)

 

;; Options Menu Settings

(cond

  ((and (string-match "XEmacs" emacs-version)

       (boundp 'emacs-major-version)

       (or (and (= emacs-major-version 19) (>= emacs-minor-version 14))

           (>= emacs-major-version 20)

       )

       (fboundp 'load-options-file))

  (load-options-file "~bak/.xemacs-options"))

)

 

(put 'eval-expression 'disabled nil)

 

;;(custom-set-faces)