Skip to content

Instantly share code, notes, and snippets.

@sheijk
Last active January 26, 2021 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheijk/d5885166bc18125bd4acac61ff6dcf48 to your computer and use it in GitHub Desktop.
Save sheijk/d5885166bc18125bd4acac61ff6dcf48 to your computer and use it in GitHub Desktop.
A simple menu to start a few apps from Emacs, including convenient profiler toggle
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Quickly start applications, etc.
(defun shk-open-buffer-in-atom ()
"Will open the given buffer using the Atom text editor."
(interactive)
(unless (buffer-file-name)
(error "Buffer has no file associated"))
(async-shell-command (format "atom %s" (buffer-file-name))))
(defun shk-profiler-toggle ()
"Start/stop the elisp profiler.
If the profiler is not running timings will be reset and
profiling started. If it is already running it will be stopped
and a report will be shown."
(interactive)
(if (profiler-running-p)
(progn
(message "Stopping profiling")
(profiler-report)
(profiler-stop))
(message "Starting profiling")
(ignore-errors
(profiler-reset))
(call-interactively 'profiler-start)))
;; TODO: check if there is a more robust approach to this
(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e/")
(autoload 'mu4e "mu4e" "Start mu4e mail client" t)
(defun shk-open-buffer-in-external ()
"Will open the current file with system default program"
(interactive)
(shell-command (format "%s %s"
(if (equal system-type 'darwin) "open" "xdg-open")
(buffer-file-name))))
(autoload 'profiler-running-p "profiler")
(transient-define-prefix shk-start-emacs-menu ()
"Menu to starte new Emacs instances"
["Emacs"
("e" "new instance" shk-start-new-emacs-instance)
("d" "debug init" shk-start-new-emacs-instance-debug-init)
("q" "no init" shk-start-new-emacs-instance-no-init)])
(transient-define-prefix shk-start-menu
"Start"
[:description
"Start"
["Shell"
("b" "shell" shell)
("s" "eshell" eshell)
("S" "cd in eshell" shk-eshell-goto-current-dir)]
["Misc"
("." "calendar" calendar)
("c" "calc" quick-calc)
("M" "mail" mu4e)
("v" "magit" magit-status)]
["External"
("x" "external" shk-open-buffer-in-external)
("e" "Emacs" shk-start-emacs-menu)
("A" "atom" shk-open-buffer-in-atom)]
["Profiler"
("p" "start" shk-profiler-toggle :if-not profiler-running-p)
("p" "stop" shk-profiler-toggle :if profiler-running-p)]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment