views:

51

answers:

2

The challenge of upgrading from Emacs 21.2 to 23.2 continues... In my .emacs I have the very convenient:

(global-set-key (quote [f4]) (quote dired-omit-toggle))

It used to work since Emacs 18... but it no longer works in Emacs 23.2:

Lisp error: (void-function dired-omit-toggle)

Any idea how I can replace this functionality in Emacs 23.2?

EmacsWiki says:

To use this mode add the following to your InitFile.

  (add-hook 'dired-load-hook
            (function (lambda () (load "dired-x"))))

and this is exactly what I have been having all these years. But Emacs 23.2 doesn't like this anymore. Any idea what could have replaced it in Emacs 23.2?

+3  A: 

Since Emacs 22, you need to call dired-omit-mode instead of dired-omit-toggle. You still need to load dired-x. From NEWS.22:

* In Dired-x, Omitting files is now a minor mode, dired-omit-mode.

The mode toggling command is bound to M-o. A new command dired-mark-omitted, bound to * O, marks omitted files. The variable dired-omit-files-p is obsoleted, use the mode toggling function instead.

Gilles
Gilles, you are a life saver. It seems that the challenges I face stem from the fact that I didn't go through Emacs 22, so its NEWS file is not right at the Emacs 23 I am trying to make work for me. Anyway, your suggestion works. I will shortly post the code that replaces it.
Android Eve
A: 

Since my upgrade from Emacs 21 to 23 is gradual, having to maintain the same .emacs for several systems, some of which use Emacs 21, and some use Emacs 23, I came up with the following code:

(GNUEmacs21
 (global-set-key (quote [f4]) (quote dired-omit-toggle))
)

(GNUEmacs22
 (global-set-key (quote [f4]) (quote dired-omit-mode))
)

(GNUEmacs23
 (global-set-key (quote [f4]) (quote dired-omit-mode))
)

GNUEmacs21, GNUEmacs22 and GNUEmacs23 are defined earlier in the .emacs file as:

(defmacro GNUEmacs23 (&rest body)
  (list 'if (string-match "GNU Emacs 23" (version))
        (cons 'progn body)))

(defmacro GNUEmacs22 (&rest body)
  (list 'if (string-match "GNU Emacs 22" (version))
        (cons 'progn body)))

(defmacro GNUEmacs21 (&rest body)
  (list 'if (string-match "GNU Emacs 21" (version))
        (cons 'progn body)))
Android Eve
I do not recommend going this route, because you have to figure out exactly what version of Emacs changed the feature. Most such incompatibilities are best resolved by testing the availability of a function or variable. Here, I would do something like `(eval-after-load "dired-x" '(if (not (fboundp 'dired-omit-toggle)) (defalias 'dired-omit-toggle 'dired-omit-mode)))`.
Gilles
Excellent suggestion. Thank you!
Android Eve