28 Feb

Open in new tab in running Carbon Emacs

Wednesday February 28th 2007, 12:13 pm
Tags: , , ,

Carbon Emacs acts like emacsclient or gnuserv by itself, i.e. it only runs one instance and opens files in this instance from Finder automatically.

A drawback of this behaviour is that the usual server-window variable of gnuserv has no effect. When using elscreen to get tabs into Emacs the desired behaviour might be to open a new tab in the running Emacs when you open a file from Finder. This can easily be done, using my intelligent-kill command (see my elscreen posting) such that files from Finder are opened in a new tab, and you can close this tab with the usual C-x C-c:

(defun create-new-tab-and-switch-to ()
  (message "New tab")
  (elscreen-create))

(defadvice mac-ae-open-documents (before mac-ae-open-documents-advice activate)
  "Create new tab before" (create-new-tab-and-switch-to))
(ad-activate ‘mac-ae-open-documents)

0 Comments

21 Nov

Open Gnus article in new tab

Tuesday November 21st 2006, 6:08 pm
Tags: , , , ,

And yet another Emacs hack: open an article from the Gnus summary buffer in another elscreen tab by pressing C-RET. Gnus does not support multiple article buffers for the same group, so I select the article below the cursor, rename the buffer to something else and restore the previous selected article. Works fine ™. Only drawback: most Gnus command like “reply” will not work, or more precisely they will be relative to the current article in the real *Article* buffer.

(defun my-show-article-other-window ()
  (interactive)
  "Show article in a seperate window from Gnus summary buffer"
  (mapcar
   (lambda (article)
     (elscreen-find-and-goto-by-buffer gnus-summary-buffer)
     (let ((show-article
            (lambda ()
              (gnus-summary-select-article nil ‘force ‘pseudo article)
              (gnus-summary-select-article-buffer)
              (let ((new-name (concat "*Article " gnus-newsgroup-name
                                      "/" (number-to-string article) "*")))
                (if (get-buffer new-name) (kill-buffer (get-buffer new-name)))
                (rename-buffer new-name)
                new-name))))
       (elscreen-create)
       (switch-to-buffer
        (save-window-excursion
          (save-excursion
            (if (gnus-buffer-live-p gnus-article-buffer)
                (let ((old-article (cdr gnus-article-current))
                      (new-name (funcall show-article)))
                  (gnus-summary-select-article nil ‘force ‘pseudo old-article)
                  new-name)
              (funcall show-article))))))
     (gnus-summary-work-articles nil))))

(define-key gnus-summary-mode-map [(control return)] ‘my-show-article-other-window)

0 Comments

21 Nov

Tabbed Emacs

Tuesday November 21st 2006, 10:29 am
Tags: , ,

You like Firefox’s tabs to clean up your screen and keep an overview of which pages are open? Of course Emacs can do that as well: elscreen.
With the following code you can open new tabs with C-t and close them with C-x C-c (yes, the way you normally quit your Emacs; Firefox uses C-w which is used in Emacs for cutting text though). Every tab can be split into windows as you like of course.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Elscreen - http://www.emacswiki.org/cgi-bin/wiki/EmacsLispScreen
(load "elscreen" "ElScreen" t)
(global-set-key (kbd "<C-tab>") ‘elscreen-toggle)
(global-set-key [(control shift right)] ‘elscreen-next)
(global-set-key [(control shift left)] ‘elscreen-previous)
(global-set-key [(control t)] ‘elscreen-create)
(elscreen-set-prefix-key "\C-j")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; C-x C-c closes frame or tab
(global-set-key "\C-x\C-c" ‘intelligent-kill)

(defun intelligent-kill ()
  "quit the same way no matter what kind of window you are on"
  (interactive)
;  (kill-buffer (buffer-name))
  (if (and (not (elscreen-one-screen-p)) (elscreen-kill))
      (message "Killed screen")
    (if (eq (car (visible-frame-list)) (selected-frame))
        ;;for parent/master frame…
        (if (> (length (visible-frame-list)) 1)
            ;;a parent with children present
            (delete-frame (selected-frame))
          ;;a parent with no children present
          (save-buffers-kill-emacs))
      ;;a child frame
      (delete-frame (selected-frame)))))

0 Comments