Emacs fiddling: show the menu-bar when the mouse is near the top of the frame

My wife is having dinner with the baby at her parents’, so I took a moment to do a bit of pure, pointless, fun hacking after reading a discussion of which emacs gui features to turn off on a site I frequent. I turn off the tool bar and the scroll bar to get as much screen real estate as possible, but leave the menu bar on, because it doesn’t take up that much space, and I occasionally use it to grab some little used feature whose full function name I don’t recall.

My idea: make the menu bar appear only if the mouse is in that general vicinity. This initial implementation is hacky and doesn’t work quite right; but it shouldn’t take much to make it work. It’s probably actually already been done somewhere, but it was fun to hack up something for the sake of hacking… something I don’t get enough time for these days.

    (defun menu-bar-show-hide-helper ()
      (if (< (cddr (mouse-pixel-position)) 20)
      (menu-bar-mode 1)
    (menu-bar-mode 0)))

    (defun menu-bar-show-hide ()
      (run-with-idle-timer 0.1 t 'menu-bar-show-hide-helper))

I’ll add fixes and updates as they are sent in.


At times, when I’m working with an HTML file – an article about programming, for instance – I need to include a snippet of code inside a <pre> tag or a <code> tag. It’s very annoying to have to indent that code by hand, and since the language may be anything from Hecl, to Erlang, to Java to C, I don’t want to use something like two-mode-mode for Emacs, so I threw the following elisp together:

(defun indent-region-as (other-mode)
  "Indent selected region as some other mode.  Used in order to indent source code contained within HTML."
  (interactive "aMode to use: ")

(let ((old-mode major-mode))
  (narrow-to-region (region-beginning) (region-end))
  (funcall other-mode)
  (indent-region (region-beginning) (region-end) nil)
  (funcall old-mode)))

To use it:

  1. Put it in your .emacs file.
  2. Select the region to indent according to the other mode.
  3. M-x indent-region-as – which will prompt you for the other mode to use. You need to give the function for that mode, such as tcl-mode, java-mode, ruby-mode or whatever.

My elisp is a bit rusty, so I’m sure it’s possible to improve the code above, but it does the job for me.