Browse Source

Correct a few typos, better support for emacs terminals

master
Peter J. Jones 1 year ago
parent
commit
c5052fc5c9
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
6 changed files with 70 additions and 135 deletions
  1. 39
    102
      bin/e
  2. 8
    0
      bin/eterm
  3. 1
    1
      bin/wait-emacs.sh
  4. 18
    27
      lisp/interactive.el
  5. 0
    1
      lisp/modes.el
  6. 4
    4
      modes/mu4e-conf.el

+ 39
- 102
bin/e View File

@@ -1,117 +1,54 @@
#!/usr/bin/env ruby
#!/bin/bash

################################################################################
require('optparse')
# A very simple wrapper around emacsclient.
set -e

################################################################################
class RemoteEmacs
option_server_name="server"
option_server_path="$HOME/.cache/emacs/server/"
option_emacs_opts=()

##############################################################################
LOCAL_SERVER_DIR = File.expand_path('~/.cache/emacs/server/')

##############################################################################
REMOTE_SERVER_FILE = File.expand_path('~/develop/emacs.server')

##############################################################################
DEFAULT_OPTIONS = {
'eval' => false,
'frame' => false,
'restart' => false,
'server' => nil,
'tty' => false,
'verbose' => false,
'version' => false,
'wait' => false,
}

##############################################################################
OptionProxy = Struct.new(*DEFAULT_OPTIONS.keys.sort.map {|k| k.to_sym})

##############################################################################
def initialize
@options = OptionProxy.new(*DEFAULT_OPTIONS.keys.sort.map {|k| DEFAULT_OPTIONS[k]})

OptionParser.new do |p|
p.on('-V', '--version', 'Show Emacs version information') {|v| @options.version = v}
p.on('-c', '--create-frame', 'Create a new Emacs frame') {|f| @options.frame = f}
p.on('-e', '--eval', 'Eval the file argument as lisp') {|e| @options.eval = e}
p.on('-h', '--help', 'This message.') {$stdout.puts(p); exit}
p.on('-n', '--no-wait', 'Don\'t wait for Emacs [default]') {@options.wait = false}
p.on('-r', '--restart', 'Restart the Emacs server') {@options.restart = true}
p.on('-s', '--server=NAME', 'Set the server name to use') {|s| @options.server = s}
p.on('-t', '--tty', 'Open a new frame on the current terminal') {|t| @options.tty = t}
p.on('-v', '--verbose', 'Enable verbose messages') {|v| @options.verbose = v}
p.on('-w', '--wait', 'Wait for Emacs to finish') {@options.wait = true}
end.parse!(ARGV)

@emacsclient = ['emacsclient']
@options.server = get_server_name
@socket_file = File.expand_path(File.join(LOCAL_SERVER_DIR, @options.server))
end

##############################################################################
def run
start_server if !File.exist?(@socket_file) || @options.restart

if !@options.frame &&
!@options.tty &&
!@options.eval &&
ARGV.empty?
then
@options.frame = true
end

@emacsclient << '--quiet' if !@options.verbose
@emacsclient << '--version' if @options.version
@emacsclient << '--tty' if @options.tty
@emacsclient << '--create-frame' if @options.frame
@emacsclient << '--eval' if @options.eval
################################################################################
usage () {
cat <<EOF
Usage: e [options] [file] -- [emacsclient options]

if !@options.wait and
!@options.tty and
!@options.eval and
!@options.version
then
@emacsclient << '--no-wait'
end
-c Open a new frame
-h This message
-s NAME Connect to server NAME
-t Open a new TTY
EOF
}

@emacsclient << "--server-file=#{@socket_file}"
################################################################################
while getopts "chs:t" o; do
case "${o}" in
c) option_emacs_opts+=("--create-frame" "--no-wait")
;;

@emacsclient.concat(ARGV)
$stdout.puts(@emacsclient.join(' ')) if @options.verbose
exec(*@emacsclient) || raise('emacsclient failed')
end
h) usage
exit
;;

##############################################################################
private
s) option_server_name=$OPTARG
;;

##############################################################################
# Figure out what server name to use.
def get_server_name
[ @options.server,
ENV['EMACS_SERVER'],
ENV['DISPLAY'] && `wmctrl -d | awk '($2 ~ /\*/) {print $NF}'`.chomp,
'server',
].find {|name| !name.nil?}
end
t) option_emacs_opts+=("--tty")
;;

##############################################################################
# Start (or restart) an Emacs server.
def start_server
command = ['emacs', "--daemon=#{@options.server}"]
*) exit 1
;;
esac
done

if @options.restart
system('pkill', '-f', command.join(' '))
end
shift $((OPTIND-1))

system(*command) || raise("failed to start Emacs!")
end
end
################################################################################
if [ ! -e "${option_server_path}${option_server_name}" ]; then
emacs --daemon="$option_server_name"
fi

################################################################################
begin
RemoteEmacs.new.run
rescue RuntimeError => e
$stderr.puts(File.basename($0) + ": ERROR: #{e}")
exit(1)
end
emacsclient --server-file="${option_server_path}${option_server_name}" \
"${option_emacs_opts[@]}" "$@"

+ 8
- 0
bin/eterm View File

@@ -0,0 +1,8 @@
#!/bin/bash

################################################################################
# Create a new Emacs frame running a terminal.
set -e

################################################################################
e -c -- --eval '(pjones:start-term)'

+ 1
- 1
bin/wait-emacs.sh View File

@@ -4,4 +4,4 @@
# execute commands without arguments. It invokes emacsclient with
# flags to open a new frame, and wait for the file to be done being
# edited.
e --wait -c "$@"
e -- --create-frame "$@"

+ 18
- 27
lisp/interactive.el View File

@@ -62,15 +62,13 @@ placing it in the kill ring)."
(back-to-indentation)
(when (= start (point)) (move-beginning-of-line 1))))

(defun pjones:start-primary-app (arg)
"Start an application like Gnus or IRC client based on the name
of the Emacs server."
(interactive "P")
(cond
((string= "gnus" server-name) (gnus arg))
((string= "irc" server-name) (pjones:irc arg))))
(defun pjones:start-mail ()
"Start an instance of mu4e."
(interactive)
(require 'mu4e)
(mu4e))

(defun pjones:irc (&optional local-only)
(defun pjones:start-irc (&optional local-only)
"Start IRC client. With an argument only start a connection to
the local bitlbee instance."
(interactive "P")
@@ -79,6 +77,12 @@ the local bitlbee instance."
(circe-maybe-connect "bitlbee")
(circe-maybe-connect "freenode")))

(defun pjones:start-term ()
"Start a new terminal buffer."
(interactive)
(term "zsh")
(rename-buffer (generate-new-buffer-name "term")))

(defun pjones:pwgen (&optional word)
"Generate and insert a password."
(interactive "P")
@@ -247,7 +251,7 @@ file. With a prefix argument kill the entire path for the file."
"Start org-agenda with my custom agenda view"
(interactive)
(require 'org)
(org-agenda nil "p"))
(org-agenda nil "c"))

;; Stolen from: http://whattheemacsd.com//key-bindings.el-01.html
(defun pjones:goto-line-with-feedback ()
@@ -277,20 +281,6 @@ If BACKWARD is non-nil delete backward instead of forward."
(if backward (kill-region end start)
(kill-region start end))))

(defun pjones:terminal (directory)
"Create a new (unique) terminal frame optionally in DIRECTORY."
(require 'term)
(let ((frame (make-frame '((name . "eterm") (window-system . x)))))
(with-selected-frame frame
(let ((buffer (get-buffer-create (concat "*temp-term-name*"))))
(with-current-buffer buffer
(cd directory)
(term-mode)
(term-exec buffer (rename-buffer "*eterm*" t) (getenv "SHELL") nil nil)
(term-char-mode))
(switch-to-buffer buffer)
(delete-other-windows)))))

(defun pjones:uuid ()
"Create a UUID, add it to the kill ring, and insert it into the
current buffer after point."
@@ -314,14 +304,15 @@ current buffer after point."
"
^OrgMode^ ^Indium^ ^Other^
-----------------------------------------
_a_: agenda _j c_: chrome _g_: app
_c_: capture _j n_: node
_a_: agenda _j c_: chrome _m_: mail
_c_: capture _j n_: node _i_: irc
"
("a" org-agenda)
("a" pjones:agenda)
("c" org-capture)
("j c" pjones:indium-start-chrome)
("j n" pjones:indium-start-node)
("g" pjones:start-primary-app))
("m" pjones:start-mail)
("i" pjones:start-irc))

(defhydra hydra-window-ops (:hint nil :color blue)
"

+ 0
- 1
lisp/modes.el View File

@@ -2,7 +2,6 @@

;; Global minor modes
(winner-mode)
(god-mode)

;; Atomically load my per-mode configuration files
(dolist (file (directory-files pjones:modes-dir t))

+ 4
- 4
modes/mu4e-conf.el View File

@@ -79,10 +79,10 @@
:match-func #'pjones:mu4e-match-func-rfa
:vars `((user-mail-address . "peter.jones@rfa.sc.gov")
(mu4e-user-mail-address-list . '("peter.jones@rfa.sc.gov"))
(mu4e-sent-folder . "/devalot/Sent Items")
(mu4e-drafts-folder . "/devalot/Drafts")
(mu4e-trash-folder . "/devalot/Deleted Items")
(mu4e-refile-folder . "/devalot/Archive")
(mu4e-sent-folder . "/rfa/Sent Items")
(mu4e-drafts-folder . "/rfa/Drafts")
(mu4e-trash-folder . "/rfa/Deleted Items")
(mu4e-refile-folder . "/rfa/Archive")
(mu4e-compose-signature . (pjones:mu4e-read-signature "scors"))
(smtpmail-smtp-server . "outlook.office365.com")
(smtpmail-smtp-service . 587)

Loading…
Cancel
Save