;;; poorman-menu.el --- -*- lexical-binding: t; -*- ;; Copyright (C) 2020 Arthur Miller ;; Author: Arthur Miller ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;;; Code: (defvar pm-menu-dir ) (defun pm-load-menu (menuname) (with-current-buffer (get-buffer-create menuname) (insert-file-contents (concat pm-menu-dir menuname)) (not-modified) (current-buffer))) (defun pm-menutest () (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-cursor "testmenu")) (defun pm-unload-menu (menuname) (let ((b (get-buffer menuname))) (if b (kill-buffer b)))) (define-minor-mode pm-minor-mode "" :keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "C-g") 'pm-quit) map)) (defun pm-hide-menu (menuframe) (make-frame-invisible)) (defun pm-quit () (interactive) (let ((b (window-buffer))) (when b (kill-buffer b))) (delete-frame (selected-frame))) (defun pm-show-at-point (menuname) (let ((pos (pos-visible-in-window-p nil nil t))) (pm-create-menu menuname (nth 0 pos) (nth 1 pos)))) (defun pm-show-at-cursor (menuname) (let ((pos (mouse-pixel-position))) (if pos (pm-create-menu menuname (cadr pos) (cddr pos)) (pm-show-at-point (menuname))))) (defun pm-create-menu (menuname x y) "Displays a menu MENUNAME as a vertical menu. If x and y are given, the menu will be shown at those coordinates. Default is current cursor position. If cursor is outside an Emacs frame window is displayed at active point." (when (not (get-buffer menuname)) (pm-load-menu menuname)) (with-current-buffer (get-buffer menuname) (pm-minor-mode) (setq tab-line-format nil) (setq mode-line-format nil) (let ((parent (selected-frame)) (child-frame ;; (make-frame `((parent-frame . ,(selected-frame)) ;; (left . ,x) ;; (top . ,y) ;; (width . 20) ;; (height . 10))))) ;; (select-frame-set-input-focus child-frame))) (make-frame `((visible . nil) ;;(parent-frame . ,(selected-frame)) (undecorated . nil))))) (fit-frame-to-buffer child-frame) (set-frame-position child-frame x y) (set-frame-parameter child-frame 'parent-frame parent) (select-frame-set-input-focus child-frame))) ) (provide 'poorman-menu) ;;; pure-menu.el ends here