;;; poor-man-menu.el --- -*- lexical-binding: t; -*- (defun pm-test () (interactive) (let ((test (get-buffer "testmenu"))) (when (not test) (with-current-buffer (get-buffer-create "testmenu") (insert "one") (newline) (insert "two") (newline) (insert "three") (newline) (insert "four")))) (pm-show-at-point "testmenu")) (define-minor-mode pm-minor-mode :keymap (let ((map (make-sparse-keymap))) map)) (defun pm-quit () (interactive) (let ((b (window-buffer))) (when b (kill-buffer b))) (delete-frame (selected-frame))) (defun pm-show-at-point (menuname) (let ((position (pos-visible-in-window-p nil nil t))) (pm-create-menu menuname (nth 0 position) (nth 1 position)))) (defun pm-show-at-cursor (menuname) (let ((cursor-pos (mouse-pixel-position))) (pm-create-menu menuname (cadr cursor-pos) (cddr cursor-pos)))) (defun pm-create-menu (menuname x y) (when (not (get-buffer menuname)) (pm-load-menu menuname)) (with-current-buffer (get-buffer menuname) (pm-minor-mode) (define-key pm-minor-mode-map (kbd "C-g") 'pm-quit) (setq tab-line-format nil) (setq mode-line-format nil) (let ((parent (selected-frame)) (child-frame (make-frame '((visible . 0) (undecorated . 0) (keep-ratio . t) (menu-bar-lines . 0) (tool-bar-lines . 0) (left-fringe . 0) (right-fringe . 0) (line-spacing . 0) (unsplittable . t) (minibuffer . nil) (no-other-frame . t) (drag-internal-border . t) (inhibit-double-buffering . t) (desktop-dont-save . t))))) (set-frame-parameter child-frame 'parent-frame parent) (fit-frame-to-buffer child-frame) (set-frame-position child-frame x y) ;;(raise-frame child-frame) ;; needs two calls to get raised AND focused (select-frame-set-input-focus child-frame) (select-frame-set-input-focus child-frame)))) (provide 'poor-man-menu)