Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Imagination Technologies's MIPS group, in the past of other companies such as Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Tuesday, October 02, 2012

Emacs functions to manipulate multiple frames on multiple displays





;; Convenient functions to manipulate multiple frames on multiple displays

;; e.g. I often run emacs with 4 frames on 4 different VNC sessions

;; and often need to delete all but the current frame.

(progn ; test idiom: defun some stuff, and then test at end of progn. can eval to test interactively
  (defun print-frame-list ()
    (interactive)
    (reduce 'concat
      (mapcar
(lambda (frame) "print frame"
 (reduce 'concat
   (mapcar (lambda (s) (format "%s" s))
     (list
"TITLE=" (frame-parameter frame 'title) "\n"
"   NAME=" (frame-parameter frame 'name) "\n"
"   explicit-name=" (frame-parameter frame 'explicit-name) "\n"
"   display=" (frame-parameter frame 'display) "\n"
"   frame-height X frame-width=" (frame-height frame) "x" (frame-width frame) "\n"
"   frame-pixel-height X frame-pixel-width=" (frame-pixel-height frame) "x" (frame-pixel-width frame) "\n"
"   visibility=" (frame-parameter frame 'visibility) "\n"
)
     )
   )
 )
(frame-list)
)
      )
    )
  (defun delete-frames-except (frame-list-to-be-deleted)
    (mapcar 'delete-frame frame-list-to-be-deleted))
  (defun non-selected-frames ()
    (remove-if 'null (mapcar (lambda (f) (if (eq (selected-frame) f) nil f)) (frame-list))))
  (defun delete-frames-except-selected ()
    "delete all frames except for the currently selected frame
useful in cleaning up frames scattered over multiple displays, e.g. multip.le VNC sessions"
    (interactive)
    (delete-frames-except (non-selected-frames))
    )
  (defun ag-mips-usual-emacs-frames ()
    "open my usual emacs frames"
    (interactive)
    (make-frame-on-display "ubuntu-uarch:1.0")
    (make-frame-on-display "ubuntu-uarch:2.0")
    ;(make-frame-on-display "ubuntu-uarch:3.0")
    (make-frame-on-display "ubuntu-uarch:4.0")
    )
  ;; test (manual, hand-checked)
  (delete-frames-except-selected)
  (ag-mips-usual-emacs-frames)
  (print-frame-list)
  )


(progn
  ;; Creating a new menu pane in the menu bar to the right of Tools menu
  (define-key-after
    global-map
    [menu-bar ag-frame-menu]
    (cons "Frames" (make-sparse-keymap "hoot hoot"))
    'tools )

  ;; Creating a menu item, under the menu by the id [menu-bar mymenu]
  (define-key
    global-map
    [menu-bar ag-frame-menu dff]
    '("delete-frames-except-selected" . delete-frames-except-selected))

  ;; creating another menu item
  (define-key
    global-map
    [menu-bar ag-frame-menu df.]
    '("delete-frame" . delete-frame))


  ;; creating another menu item
  (define-key
    global-map
    [menu-bar ag-frame-menu uf]
    '("usual frames" . ag-mips-usual-emacs-frames))
  )

No comments: