From 32953a9faf6c1145c05dee83af66407dc87b4630 Mon Sep 17 00:00:00 2001 From: zach mandeville Date: Thu, 7 May 2020 22:38:26 +0000 Subject: [PATCH 01/13] remove agenda file overwrite in org config --- layers/ii-org/config.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layers/ii-org/config.el b/layers/ii-org/config.el index 980af35..42e9c8f 100644 --- a/layers/ii-org/config.el +++ b/layers/ii-org/config.el @@ -13,7 +13,7 @@ org-enable-epub-support t ;; add all org files in our projects' org folder to agenda ;; this adds some searching and navigation super powers (try SPC aom) - org-agenda-files '("~/apisnoop/docs") + ;; org-agenda-files '("~/apisnoop/docs") ) ;;; Set reasonable (for ii) default header args From 5f0bee9f54a6a046aa08cf774f85bc1f81e779b9 Mon Sep 17 00:00:00 2001 From: zach mandeville Date: Thu, 7 May 2020 22:38:51 +0000 Subject: [PATCH 02/13] add initial ii mate layer --- layers/ii-mate/README.org | 25 + layers/ii-mate/layers.el | 3 + layers/ii-mate/local/iterm/iterm.el | 105 +++++ layers/ii-mate/local/ob-tmate/ob-tmate.el | 543 ++++++++++++++++++++++ layers/ii-mate/local/osc52e/osc52e.el | 159 +++++++ layers/ii-mate/packages.el | 75 +++ 6 files changed, 910 insertions(+) create mode 100644 layers/ii-mate/README.org create mode 100644 layers/ii-mate/layers.el create mode 100644 layers/ii-mate/local/iterm/iterm.el create mode 100644 layers/ii-mate/local/ob-tmate/ob-tmate.el create mode 100644 layers/ii-mate/local/osc52e/osc52e.el create mode 100644 layers/ii-mate/packages.el diff --git a/layers/ii-mate/README.org b/layers/ii-mate/README.org new file mode 100644 index 0000000..0e8a25e --- /dev/null +++ b/layers/ii-mate/README.org @@ -0,0 +1,25 @@ +#+TITLE: ii-mate layer +# Document tags are separated with "|" char +# The example below contains 2 tags: "layer" and "web service" +# Avaliable tags are listed in /.ci/spacedoc-cfg.edn +# under ":spacetools.spacedoc.config/valid-tags" section. +#+TAGS: layer|web service + +# The maximum height of the logo should be 200 pixels. +[[img/ii-mate.png]] + +# TOC links should be GitHub style anchors. +* Table of Contents :TOC_4_gh:noexport: +- [[#description][Description]] + - [[#features][Features:]] +- [[#install][Install]] + +* Description +This layer adds support for literate pair programming when doing dev-ops work. It is centered around using tmate in org src blocks, so that you can easily document code and see it executed on its own screen. +** Features: + - run tmate src blocks that will auto-trigger a tmate session to share + +* Install +To use this configuration layer, add it to your =~/.spacemacs=. You will need to +add =ii-mate= to the existing =dotspacemacs-configuration-layers= list in this +file. diff --git a/layers/ii-mate/layers.el b/layers/ii-mate/layers.el new file mode 100644 index 0000000..5cf3c24 --- /dev/null +++ b/layers/ii-mate/layers.el @@ -0,0 +1,3 @@ +;; L A Y E R S + +(configuration-layer/declare-layer 'org) diff --git a/layers/ii-mate/local/iterm/iterm.el b/layers/ii-mate/local/iterm/iterm.el new file mode 100644 index 0000000..7e51b01 --- /dev/null +++ b/layers/ii-mate/local/iterm/iterm.el @@ -0,0 +1,105 @@ +;;; iterm.el - Send text to a running iTerm instance + +(require 'pcase) +(require 'thingatpt) + +(defvar iterm-default-thing 'line + "The \"thing\" to send if no region is active. +Can be any symbol understood by `bounds-of-thing-at-point'.") + +(defvar iterm-empty-line-regexp "^[[:space:]]*$" + "Regexp to match empty lines, which will not be sent to iTerm. +Set to nil to disable removing empty lines.") + +(defun iterm-escape-string (str) + (let* ((str (replace-regexp-in-string "\\\\" "\\\\" str nil t)) + (str (replace-regexp-in-string "\"" "\\\"" str nil t)) + (str (replace-regexp-in-string "'" "\\'" str nil t))) + str)) + +(defun iterm-last-char-p (str char) + (let ((length (length str))) + (and (> length 0) + (char-equal (elt str (- length 1)) char)))) + +(defun iterm-chop-newline (str) + (let ((length (length str))) + (if (iterm-last-char-p str ?\n) + (substring str 0 (- length 1)) + str))) + +(defun iterm-maybe-add-newline (str) + (if (iterm-last-char-p str ? ) + (concat str "\n") + str)) + +(defun iterm-handle-newline (str) + (iterm-maybe-add-newline (iterm-chop-newline str))) + +(defun iterm-maybe-remove-empty-lines (str) + (if iterm-empty-line-regexp + (let ((regexp iterm-empty-line-regexp) + (lines (split-string str "\n"))) + (mapconcat #'identity + (delq nil (mapcar (lambda (line) + (unless (string-match-p regexp line) + line)) + lines)) + "\n")) + str)) + +(defun iterm-new-window-send-string (str) + "Send STR to a running iTerm instance." + (let* ((str (iterm-maybe-remove-empty-lines str)) + (str (iterm-handle-newline str)) + (str (iterm-escape-string str))) + (let ((cmd (concat "osascript " + "-e 'tell app \"iTerm\"' " + "-e 'tell current window' " + "-e 'create window with default profile' " + "-e $'tell current session to write text \"" str "\"' " + "-e 'end tell' " + "-e 'end tell' "))) + (shell-command cmd)))) + +(defun iterm-send-string (str) + "Send STR to a running iTerm instance." + (let* ((str (iterm-maybe-remove-empty-lines str)) + (str (iterm-handle-newline str)) + (str (iterm-escape-string str))) + (let ((cmd (concat "osascript " + "-e 'tell app \"iTerm\"' " + "-e 'tell current window' " + "-e 'tell current session' " + "-e $'write text \"" str "\"' " + "-e 'end tell' " + "-e 'end tell' " + "-e 'end tell' "))) + (shell-command cmd) + ))) + +(defun iterm-text-bounds () + (pcase-let ((`(,beg . ,end) (if (use-region-p) + (cons (region-beginning) (region-end)) + (bounds-of-thing-at-point + iterm-default-thing)))) + (list beg end))) + +(defun iterm-send-text (beg end) + "Send buffer text in region from BEG to END to iTerm. +If called interactively without an active region, send text near +point (determined by `iterm-default-thing') instead." + (interactive (iterm-text-bounds)) + (let ((str (buffer-substring-no-properties beg end))) + (iterm-send-string str)) + (forward-line 1)) + +(defun iterm-send-text-ruby (beg end) + "Send buffer text in region from BEG to END to iTerm. +If called interactively without an active region, send text near +point (determined by `iterm-default-thing') instead." + (interactive (iterm-text-bounds)) + (let ((str (buffer-substring-no-properties beg end))) + (iterm-send-string (concat "begin\n" str "\nend"))) + (forward-line 1)) +(provide 'iterm) diff --git a/layers/ii-mate/local/ob-tmate/ob-tmate.el b/layers/ii-mate/local/ob-tmate/ob-tmate.el new file mode 100644 index 0000000..e28049d --- /dev/null +++ b/layers/ii-mate/local/ob-tmate/ob-tmate.el @@ -0,0 +1,543 @@ +;;; ob-tmate.el --- Babel Support for Interactive Terminal -*- lexical-binding: t; -*- + +;; Copyright (C) 2009-2017 Free Software Foundation, Inc. +;; Copyright (C) 2017 Allard Hendriksen + +;; Author: Allard Hendriksen +;; Keywords: literate programming, interactive shell, tmate +;; URL: https://github.com/ahendriksen/ob-tmate +;; Version: 0.1.5 +;; Package-Version: 20200206.109 +;; Package-X-Original-version: 0.1.5 +;; Package-Requires: ((emacs "25.1") (seq "2.3") (s "1.9.0")) + +;; This file is NOT part of GNU Emacs. + +;; 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: + +;; Org-Babel support for tmate. +;; +;; Heavily inspired by 'eev' from Eduardo Ochs and ob-screen.el from +;; Benjamin Andresen. +;; +;; See documentation on https://github.com/ahendriksen/ob-tmate +;; +;; You can test the default setup with +;; M-x org-babel-tmate-test RET + +;;; Code: +(require 'ob) +(require 'seq) +(require 'osc52e) +(require 'iterm) + +(defcustom org-babel-tmate-location "tmate" + "The command location for tmate. +Change in case you want to use a different tmate than the one in your $PATH." + :group 'org-babel + :type 'string) + +(defcustom org-babel-tmate-session-prefix "" + "The string that will be prefixed to tmate session names started by ob-tmate." + :group 'org-babel + :type 'string) + +(defun default-org-babel-tmate-terminal() + "What terminal should we use as a default" + (cond ((string= system-type "darwin") (concat "iterm")) + ((string= system-type "gnu/linux") + (if ;; incluster + (file-exists-p "/var/run/secrets/kubernetes.io/serviceaccount/namespace") + (concat "osc52") + (concat "xterm") + )) + (t (concat "xterm")))) + +(defcustom org-babel-tmate-terminal (default-org-babel-tmate-terminal) + "This is the terminal that will be spawned." + :group 'org-babel + :type 'string) + +(defcustom org-babel-tmate-terminal-opts '("--") + "The list of options that will be passed to the terminal." + :group 'org-babel + :type 'list) + + +(defvar org-babel-default-header-args:tmate + '((:results . "silent") + (:session . "tmate") + (:window . "i") + (:dir . ".") + (:socket . nil) + ) + "Default arguments to use when running tmate source blocks.") + +(add-to-list 'org-src-lang-modes '("tmate" . sh)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; org-babel interface +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun org-babel-execute:tmate (body params) + "Send a block of code via tmate to a terminal using Babel. +\"default\" session is used when none is specified. +Argument BODY the body of the tmate code block. +Argument PARAMS the org parameters of the code block." + (message "Sending source code block to interactive terminal session...") + (save-window-excursion + (let* ( + (socket (cdr (assq :socket params))) + (dir (cdr (assq :dir params))) + (session (cdr (assq :session params))) + (window (cdr (assq :window params))) + (socket (if socket + (expand-file-name socket) + (ob-tmate--tmate-socket session) + )) + ;; (tmate-command (concat org-babel-tmate-location " -S " socket + ;; " attach-session || read X") + (ob-session (ob-tmate--create + :session session :window window :socket socket)) + (session-alive (ob-tmate--session-alive-p ob-session)) + (window-alive (ob-tmate--window-alive-p ob-session))) + ;; Create tmate session and window if they do not yet exist + ;; Start terminal window if the session does not yet exist + (message "OB-TMATE: Checking for session: %S" session-alive) + (unless session-alive + (progn + (message "OB-TMATE: create-session") + (ob-tmate--create-session session dir socket) + (ob-tmate--start-terminal-window ob-session) + (y-or-n-p "Has a terminal started and shown you a url?") + (gui-select-text (ob-tmate--ssh-url ob-session)) + (osc52-interprogram-cut-function (concat (ob-tmate--ssh-url ob-session) " # " (ob-tmate--web-url ob-session))) + (if (y-or-n-p "Open browser for url?") + (browse-url (ob-tmate--web-url ob-session)) + ) + ) + ) + (message "OB-TMATE: Checking for window: %S" window-alive) + (unless window-alive + (progn + (message "OB-TMATE: create-window")) + (ob-tmate--create-window ob-session dir) + ;; (while (not (ob-tmate--window-alive-p ob-session))) + ) + ;; Wait until tmate window is available + ;; Disable window renaming from within tmate + ;; (ob-tmate--disable-renaming ob-session) + (ob-tmate--send-body + ob-session (org-babel-expand-body:generic body params))))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ob-tmate object +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(cl-defstruct (ob-tmate- (:constructor ob-tmate--create) + (:copier ob-tmate--copy)) + session + window + socket) + +(defun ob-tmate--tmate-session (org-session) + "Extract tmate session from ORG-SESSION string." + (let* ((session (car (split-string org-session ":")))) + (concat org-babel-tmate-session-prefix + (if (string-equal "" session) "default" session)))) +(defun ob-tmate--tmate-window (org-session) + "Extract tmate window from ORG-SESSION string." + (let* ((window (cadr (split-string org-session ":")))) + (if (string-equal "" window) nil window))) +(defun ob-tmate--tmate-socket (org-session) + "Extract tmate window from ORG-SESSION string." + (let* ( + (session-name (car (split-string org-session ":"))) + ) + (concat temporary-file-directory user-login-name "." session-name ".tmate" ) + )) + +(defun ob-tmate--from-session-window-socket (session window socket) + "Create a new ob-tmate-session object from ORG-SESSION specification. +Required argument SOCKET: the location of the tmate socket." + (ob-tmate--create :session session :window window :socket socket) + ) + +(defun ob-tmate--window-default (ob-session) + "Extracts the tmate window from the ob-tmate- object. +Returns `org-babel-tmate-default-window-name' if no window specified. + +Argument OB-SESSION: the current ob-tmate session." + (if (ob-tmate--window ob-session) + (ob-tmate--window ob-session) + org-babel-tmate-default-window-name)) + +(defun ob-tmate--target (ob-session) + "Constructs a tmate target from the `ob-tmate-' object. + +If no window is specified, use first window. + +Argument OB-SESSION: the current ob-tmate session." + (let* ((target-session (ob-tmate--session ob-session)) + (window (ob-tmate--window-default ob-session)) + (target-window (if window (concat "=" window) "^"))) + (concat target-session ":" target-window))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Process execution functions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun ob-tmate--execute (ob-session &rest args) + "Execute a tmate command with arguments as given. + +Argument OB-SESSION: the current ob-tmate session. +Optional command-line arguments can be passed in ARGS." + (message "OBSESSION: %S" ob-session) + (message "OBSESSION ARGS: %S" args) + (if (ob-tmate--socket ob-session) + (progn + (message (concat "OB-TMATE: execute on provided socket: => " (ob-tmate--socket ob-session))) + (message (concat "OB-TMATE: execute args: => " (string-join args " "))) + (message (concat "OB-TMATE: applying 'start-process")) + (setenv "TMUX") ;unset tmux env so this can be run from within a tmux session without complaint + (apply 'start-process "ob-tmate" "*Messages*" + org-babel-tmate-location + "-S" (ob-tmate--socket ob-session) + args) + ) + (progn + (message (concat "OB-TMATE: execute args: => " (string-join args " "))) + ;; (message (concat "OB-TMATE: execute ob-session: => " ob-session)) + (message (concat "OB-TMATE: execute start-process:" (ob-tmate--socket ob-session))) + (setenv "TMUX") + (apply 'start-process + "ob-tmate" "*Messages*" org-babel-tmate-location args))) + ) + +(defun ob-tmate--execute-string (ob-session &rest args) + "Execute a tmate command with arguments as given. +Returns stdout as a string. + +Argument OB-SESSION: the current ob-tmate session. Optional +command-line arguments can be passed in ARGS and are +automatically space separated." + (let* ((socket (ob-tmate--socket ob-session)) + (args (if socket (cons "-S" (cons socket args)) args))) + (message "OB_TMATE: execute-string %S" args) + (shell-command-to-string + (concat org-babel-tmate-location " " + (string-join args " "))))) + +(defun ob-tmate--start-terminal-window-iterm (ob-session) + "Start a terminal window in iterm" + (let* ((socket (ob-tmate--socket ob-session)) + ) + (iterm-new-window-send-string + (concat + "tmate " + ;; "-CC " ; use Control Mode... very beta + "-S " socket + " attach-session" ; || bash" + )))) + +(defun ob-tmate--start-terminal-window-xterm (ob-session) + ;; TODO update docstrings + "Start a terminal window in iterm" + (let* ((process-name (concat "org-babel: terminal")) + (socket (ob-tmate--socket ob-session)) + (target (ob-tmate--target ob-session)) + ) + (start-process process-name "*tmate-terminal*" + "xterm" + "-T" target + "-e" + (concat org-babel-tmate-location " -S " socket + " attach-session || read X") + ) + ) + ) +(defun ob-tmate--start-terminal-window-osc52 (ob-session) + "Start a terminal window in iterm" + (let* ((socket (ob-tmate--socket ob-session)) + (tmate-command (concat org-babel-tmate-location " -S " socket + " attach-session || read X") + ) + (osc52-interprogram-cut-function tmate-command) + ) + )) +(defun ob-tmate--start-terminal-window (ob-session) + "Start a TERMINAL window with tmate attached to session. + +Argument OB-SESSION: the current ob-tmate session." + (message "OB-TMATE: start-terminal-window") + (cond + ((string= org-babel-tmate-terminal "iterm") (ob-tmate--start-terminal-window-iterm ob-session)) + ((string= org-babel-tmate-terminal "xterm") (ob-tmate--start-terminal-window-xterm ob-session)) + ((string= org-babel-tmate-terminal "osc52") (ob-tmate--start-terminal-window-osc52 ob-session)) + ((string= org-babel-tmate-terminal "web") (ob-tmate--start-terminal-window-osc52 ob-session)) + (t (message "We didn't find a supported terminal type")) + ) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Tmate interaction +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun ob-tmate--create-session (session-name session-dir session-socket) + "Create a tmate session if it does not yet exist. + +Argument OB-SESSION: the current ob-tmate session." + ;; (unless (ob-tmate--session-alive-p ob-session) + ;; This hack gets us a tmate_ssh string + ;; tmate -S /tmp/tmate.sock new-session -d ; tmate -S /tmp/tmate.sock wait tmate-ready ; tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}' + (message "OB-TMATE: Creating new / connect to existing tmate session") + ;; (message (concat "OB-TMATE: ob-session" ob-session)) + (message "OB-TMATE: ob-tmate--create-session name,dir,socket => %S,%S,%S" session-name session-dir session-socket) + ;; TODO: temporarily unset this tmux env rather than globally + (setenv "TMUX") ;unset tmux env so this can be run from within a tmux session without complaint + (start-process-shell-command + (concat session-name "-tmate-process") + (concat "**" session-name "-tmate-process**") + (concat "nohup tmate" + ;; " -n " "init"; session-window + ;; " -F -v" + " -v" + ;; " -d -v" + " -S " session-socket + " new-session" + " -d -P -F '#{tmate_ssh}:#{tmate_web}'" + " -s " session-name + " -c " session-dir + " -n 0 " ; This is window 0 + " bash -c \"" ; begin command + "( " ; start wrap to display errors + "echo Waiting for tmate..." ; wait for tmate ready + " && " + ;; wait for tmate to be fully ready + "tmate wait tmate-ready " + " && " + "echo '\nShare this only with people you trust:'" + " && " + "tmate display -p '#{tmate_ssh} # " session-name "'" + " && " + "tmate display -p '#{tmate_web} # " session-name "'" + " && " + "echo '\nShare this read only connection otherwise:'" + " && " + "tmate display -p '#{tmate_ssh_ro} # " session-name "'" + " && " + "tmate display -p '#{tmate_web_ro} # " session-name "'" + " && " + ;; Let folks know what to do with this + "echo '\nShare the above connection with a friend and check huemacs'" + " ) 2>&1" ; end wrap to display errors + " && " + "read X" ; need to hit enter to continue + "\"" ; end command + ) + ) + ;;;;;; INSTALL tmate hook for when a client attaches + ;; Wait for tmate to be ready + ;; This means tmate ssh/web urls are handy + ;; tmate -S $TMATE_SOCKET wait-for tmate-ready + ;; Unset this type of hook globally + ;; tmate -S $TMATE_SOCKET set-hook -ug client-attached # unset + ;; When new client-attaches, create new window and run osc52-tmate.sh + ;; tmux set-environment -g PATH "" + ;; tmate -S $TMATE_SOCKET set-hook -g client-attached 'run-shell "tmate new-window osc52-tmate.sh"' + + ;; (ob-tmate--execute ob-session + ;; "new-session" + ;; ;; "-A" ;; attach if it already exists (d) + ;; "-d" ;; just create the session, don't attach. + ;; ;; "-S" (ob-tmate--socket ob-session) + ;; ;; "-S" "/tmp/ob-tmate-socket" ;; Static for now + ;; ;; "-u" ;; UTF-8 please... only in newer tmux + ;; ;; "-vv" ;; Logs please... also only in newer tmux + ;; "-c" (expand-file-name session-dir) + ;; "-s" (ob-tmate--session ob-session) + ;; "-n" (ob-tmate--window-default ob-session) + ;; ) + ;; (message "OB-TMATE: Waiting for tmate to be ready") + ;; (ob-tmate--execute ob-session "wait" "tmate-ready") + ;; how can we capture this? + ;; (setq ob-tmate-ssh-string (ob-tmate--execute-string ob-session + ;; "display" "-p" "#{tmate_ssh}" + ;; )) + ;; (message (concat "OB-TMATE: " ob-tmate-ssh-string)) + ) + + +(defun ob-tmate--create-window (ob-session session-dir) + "Create a tmate window in session if it does not yet exist. + +Argument OB-SESSION: the current ob-tmate session." + (unless (ob-tmate--window-alive-p ob-session) + (message "tmate execute session") + (ob-tmate--execute ob-session + ;; "-S" (ob-tmate--socket ob-session) + "new-window" + "-c" (expand-file-name session-dir) + ;; "-c" (expand-file-name "~") ;; start in home directory + "-n" (ob-tmate--window-default ob-session)))) + +(defun ob-tmate--set-window-option (ob-session option value) + "If window exists, set OPTION for window. + +Argument OB-SESSION: the current ob-tmate session." + (when (ob-tmate--window-alive-p ob-session) + (ob-tmate--execute ob-session + ;; "-S" (ob-tmate--socket ob-session) + "new-window" + "set-window-option" + "-t" (ob-tmate--window-default ob-session) + option value))) + +(defun ob-tmate--disable-renaming (ob-session) + "Disable renaming features for tmate window. + +Disabling renaming improves the chances that ob-tmate will be able +to find the window again later. + +Argument OB-SESSION: the current ob-tmate session." + (progn + (ob-tmate--set-window-option ob-session "allow-rename" "off") + (ob-tmate--set-window-option ob-session "automatic-rename" "off"))) + +(defun ob-tmate--send-keys (ob-session line) + "If tmate window exists, send a LINE of text to it. + +Argument OB-SESSION: the current ob-tmate session." + (when (ob-tmate--window-alive-p ob-session) + (progn + (ob-tmate--execute ob-session + "select-window" + "-t" (ob-tmate--window-default ob-session)) + (ob-tmate--execute ob-session + ;; "-S" (ob-tmate--socket ob-session) + "send-keys" + "-l" + "-t" (ob-tmate--window-default ob-session) + line "\n") + ))) + +(defun ob-tmate--send-body (ob-session body) + "If tmate window (passed in OB-SESSION) exists, send BODY to it. + +Argument OB-SESSION: the current ob-tmate session." + (let ((lines (split-string body "[\n\r]+"))) + ;; select-window before send-keys + ;; send-keys doesn't support sending to a window + () + (when (ob-tmate--window-alive-p ob-session) + (mapc (lambda (l) (ob-tmate--send-keys ob-session l)) lines)) + )) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Tmate interrogation +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun start-process--advice (name buffer program &rest program-args) + "figure out how the process is being called" + (message "%S %S %S %S" name buffer program (string-join program-args " ")) + ) +(advice-add 'start-process :after 'start-process--advice) +(advice-remove 'start-process 'advice-start--process) + + +(defun ob-tmate--session-alive-p (ob-session) + "Check if SESSION exists by parsing output of \"tmate ls\". + +Argument OB-SESSION: the current ob-tmate session." + (message (concat "OB-TMATE: session-alive-p socket: " (ob-tmate--socket ob-session))) + ;; session check is a bit simpler with tmate + ;; There is only one session per socket + ;; if we can 'tmate ls' and return zero, we are good + (= 0 (apply 'call-process org-babel-tmate-location nil nil nil + "-S" (ob-tmate--socket ob-session) + '("ls")) + )) + +(defun ob-tmate--ssh-url (ob-session) + "Retrieve the ssh # http://url/session for the ob-session" + (ob-tmate--execute-string ob-session + "display" + "-p '#{tmate_ssh}'" + )) +(defun ob-tmate--web-url (ob-session) + "Retrieve the ssh # http://url/session for the ob-session" + (substring (ob-tmate--execute-string ob-session + "display" + "-p '#{tmate_web}'" + ) + 0 -1)) + +(defun ob-tmate--window-alive-p (ob-session) + "Check if WINDOW exists in tmate session. + +If no window is specified in OB-SESSION, returns 't." + (let* ( + (window (ob-tmate--window-default ob-session)) + (target (ob-tmate--target ob-session)) + ;; This appears to hang if we let it run early + (output (ob-tmate--execute-string ob-session + "list-windows" + "-F '#W'" + )) + ) + ;; (y-or-n-p (concat "Is {" target "} alive?")) + (string-match-p (concat window "\n") output) + ) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Test functions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun ob-tmate--open-file (path) + "Open file as string. + +Argument PATH: the location of the file." +(with-temp-buffer + (insert-file-contents-literally path) + (buffer-substring (point-min) (point-max)))) + +(defun ob-tmate--test () + "Test if the default setup works. The terminal should shortly flicker." + (interactive) + (let* ((random-string (format "%s" (random 99999))) + (tmpfile (org-babel-temp-file "ob-tmate-test-")) + (body (concat "echo '" random-string "' > " tmpfile)) + tmp-string) + (org-babel-execute:tmate body org-babel-default-header-args:tmate) + ;; XXX: need to find a better way to do the following + (while (or (not (file-readable-p tmpfile)) + (= 0 (length (ob-tmate--open-file tmpfile)))) + ;; do something, otherwise this will be optimized away + (format "org-babel-tmate: File not readable yet.")) + (setq tmp-string (ob-tmate--open-file tmpfile)) + (delete-file tmpfile) + (message (concat "org-babel-tmate: Setup " + (if (string-match random-string tmp-string) + "WORKS." + "DOESN'T work."))))) + +(provide 'ob-tmate) + + + +;;; ob-tmate.el ends here diff --git a/layers/ii-mate/local/osc52e/osc52e.el b/layers/ii-mate/local/osc52e/osc52e.el new file mode 100644 index 0000000..1b18406 --- /dev/null +++ b/layers/ii-mate/local/osc52e/osc52e.el @@ -0,0 +1,159 @@ +;;;; This script can be loaded during emacs initialization to automatically +;;;; send `kill-region' and `kill-ring-save' regions to your system clipboard. +;;;; The OSC 52 terminal escape sequence is used to transfer the selection from +;;;; emacs to the host terminal. + +;;;; It is based off of the osc52.el copyright the Chromium OS authors, but +;;;; was modified to add support for tmux, graphical displays, and +;;;; multi-byte strings. + +;;;; It works in hterm, xterm, and other terminal emulators which support the +;;;; sequence. + +;;;; It also works under screen, via `osc52-select-text-dcs' and tmux via +;;;; `osc52-select-text-tmux', as long as the terminal supports OSC 52. + +;;;; Call `osc52-set-cut-function' to activate. + +(defcustom osc52-max-sequence 100000 + "Maximum length of the OSC 52 sequence. + +The OSC 52 sequence requires a terminator byte. Some terminals will ignore or +mistreat a terminated sequence that is longer than a certain size, usually to +protect users from runaway sequences. + +This variable allows you to tweak the maximum number of bytes that will be sent +using the OSC 52 sequence. + +If you select a region larger than this size, it won't be copied to your system +clipboard. Since clipboard data is base 64 encoded, the actual number of +characters that can be copied is 1/3 of this value.") + +(defcustom osc52-multiplexer 'tmux + "Select which terminal multiplexer should be used when creating OSC 52 sequences. Device control string escape sequences are only used when the value of the environment variable TERM starts with the string \"screen\". + +If set to 'tmux, a tmux DCS escape sequence will be generated, otherwise a screen DCS will be used.") + +(defun osc52-select-text (string &optional replace yank-handler) + "Copy STRING to the system clipboard using the OSC 52 escape sequence. + +Set `interprogram-cut-function' to this when using a compatible terminal, and +your system clipboard will be updated whenever you copy a region of text in +emacs. + +If the resulting OSC 52 sequence would be longer than +`osc52-max-sequence', then the STRING is not sent to the system +clipboard. + +This function sends a raw OSC 52 sequence and will work on a bare terminal +emulators. It does not work on screen or tmux terminals, since they don't +natively support OSC 52." + (let ((b64-length (+ (* (length string) 3) 2))) + (if (<= b64-length osc52-max-sequence) + (send-string-to-terminal + (concat "\e]52;c;" + (base64-encode-string string t) + "\07")) + (message \"Selection too long to send to terminal %d\" b64-length) + (sit-for 2)))) + +(defun osc52-select-text-dcs (string &optional replace yank-handler) + "Copy STRING to the system clipboard using the OSC 52 escape sequence, for +screen users. + +Set `interprogram-cut-function' to this when using the screen program, and your +system clipboard will be updated whenever you copy a region of text in emacs. + +If the resulting OSC 52 sequence would be longer than +`osc52-max-sequence', then the STRING is not sent to the system +clipboard. + +This function wraps the OSC 52 in a Device Control String sequence. This causes +screen to pass the wrapped OSC 52 sequence along to the host termianl. This +function also chops long DCS sequences into multiple smaller ones to avoid +hitting screen's max DCS length." + (let ((b64-length (+ (* (length string) 3) 2))) + (if (<= b64-length osc52-max-sequence) + (send-string-to-terminal + (concat "\eP\e]52;c;" + (replace-regexp-in-string + "\n" "\e\\\\\eP" + (base64-encode-string (encode-coding-string string 'binary))) + "\07\e\\")) + (message "Selection too long to send to terminal %d" b64-length) + (sit-for 2)))) + +(defun osc52-select-text-tmux (string &optional replace yank-handler) + "Copy STRING to the system clipboard using the OSC 52 escape sequence, for +tmux users. + +Set `interprogram-cut-function' to this when using the screen program, and your +system clipboard will be updated whenever you copy a region of text in emacs. + +If the resulting OSC 52 sequence would be longer than +`osc52-max-sequence', then the STRING is not sent to the system +clipboard. + +This function wraps the OSC 52 in a Device Control String sequence. This causes +screen to pass the wrapped OSC 52 sequence along to the host termianl. This +function also chops long DCS sequences into multiple smaller ones to avoid +hitting screen's max DCS length." + (let ((b64-length (+ (* (length string) 3) 2))) + (if (<= b64-length osc52-max-sequence) + (send-string-to-terminal + (concat "\ePtmux;\e\e]52;c;" + (base64-encode-string (encode-coding-string string 'binary) + t) + "\a\e\\")) + (message "Selection too long to send to terminal %d" b64-length) + (sit-for 2)))) + +(defvar osc52-cut-function) + +(defun osc52-interprogram-cut-function (string &optional replace yank-handler) + (if (display-graphic-p) + (x-select-text string) + (funcall osc52-cut-function string))) + +(defun osc52-set-cut-function () + "Initialize the `interprogram-cut-function' based on the value of +`display-graphic-p' and the TERM environment variable." + (interactive) + + ;; Look `initial-environment' instead of `(getenv "TERM")', + ;; because emacs might set it to "dumb" internally. + ;; `inital-environment' has the pure value when it started. + (let ((term + ;; Make term == "" instead of nil, when no TERM environment variable + (or (ignore-errors + (replace-regexp-in-string + "^TERM=" "" + (dolist (env initial-environment) + (if (string-match "^TERM=" env) (return env))) + 'fixedcase)) + ""))) + + (setq osc52-cut-function + ;; If `TERM' contains "tmux", they should use tmux. + (if (string-match "tmux" term) + 'osc52-select-text-tmux + + ;; Otherwise, if the `TERM' starts from "screen", + ;; they might actually use screen, but perhaps tmux. + ;; They have to set actual terminal by `osc52-multiplexer' + (if (string-match "^screen" term) + (if (equal osc52-multiplexer 'tmux) + 'osc52-select-text-tmux + 'osc52-select-text-dcs) + + ;; No terminal multiplexer. + 'osc52-select-text)))) + + (setq interprogram-cut-function 'osc52-interprogram-cut-function)) + +(defun osc52-send-region-to-clipboard (START END) + "Copy the region to the system clipboard using the OSC 52 escape sequence." + (interactive "r") + (osc52-interprogram-cut-function (buffer-substring-no-properties + START END))) +(provide 'osc52e) diff --git a/layers/ii-mate/packages.el b/layers/ii-mate/packages.el new file mode 100644 index 0000000..e963215 --- /dev/null +++ b/layers/ii-mate/packages.el @@ -0,0 +1,75 @@ +;;; packages.el --- ii-mate layer packages file for Spacemacs. +;; +;; Copyright (c) 2012-2018 Sylvain Benner & Contributors +;; +;; Author: +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +;;; Commentary: + +;; See the Spacemacs documentation and FAQs for instructions on how to implement +;; a new layer: +;; +;; SPC h SPC layers RET +;; +;; +;; Briefly, each package to be installed or configured by this layer should be +;; added to `ii-mate-packages'. Then, for each package PACKAGE: +;; +;; - If PACKAGE is not referenced by any other Spacemacs layer, define a +;; function `ii-mate/init-PACKAGE' to load and initialize the package. + +;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so +;; define the functions `ii-mate/pre-init-PACKAGE' and/or +;; `ii-mate/post-init-PACKAGE' to customize the package as it is loaded. + +;;; Code: + +(defconst ii-mate-packages + '((iterm :location local) + (ob-tmate :location local) + (osc52e :location local)) + "The list of Lisp packages required by the ii-mate layer. + +Each entry is either: + +1. A symbol, which is interpreted as a package to be installed, or + +2. A list of the form (PACKAGE KEYS...), where PACKAGE is the + name of the package to be installed or loaded, and KEYS are + any number of keyword-value-pairs. + + The following keys are accepted: + + - :excluded (t or nil): Prevent the package from being loaded + if value is non-nil + + - :location: Specify a custom installation location. + The following values are legal: + + - The symbol `elpa' (default) means PACKAGE will be + installed using the Emacs package manager. + + - The symbol `local' directs Spacemacs to load the file at + `./local/PACKAGE/PACKAGE.el' + + - A list beginning with the symbol `recipe' is a melpa + recipe. See: https://github.com/milkypostman/melpa#recipe-format") +(defun ii-mate/init-iterm () + (use-package iterm)) + +(defun ii-mate/init-ob-tmate () + (use-package ob-tmate + :after (iterm osc52e))) + +(defun ii-mate/init-osc52e () + (use-package osc52e)) + +(defun ii-mate/post-init-osc52e () + (osc52-set-cut-function)) + +;;; packages.el ends here From 7e2053b457d002c705cbaae5145d4e6e2756283e Mon Sep 17 00:00:00 2001 From: zach mandeville Date: Thu, 7 May 2020 22:39:03 +0000 Subject: [PATCH 03/13] add ii-mate to our .spacemacs --- init.el | 1 + 1 file changed, 1 insertion(+) diff --git a/init.el b/init.el index 1a79c7f..00c39a3 100644 --- a/init.el +++ b/init.el @@ -59,6 +59,7 @@ This function should only modify configuration layer settings." treemacs ii-elpa ii-go + ii-mate ii-org ii-org-capture ii-sql From 67c175cfcb8662258d5f32ca2fd960e68f3f881d Mon Sep 17 00:00:00 2001 From: zach mandeville Date: Thu, 7 May 2020 22:39:15 +0000 Subject: [PATCH 04/13] update work diary --- org/setup-with-zz.org | 273 ++++++++---------------------------------- 1 file changed, 53 insertions(+), 220 deletions(-) diff --git a/org/setup-with-zz.org b/org/setup-with-zz.org index dfe3d59..fff7ed7 100644 --- a/org/setup-with-zz.org +++ b/org/setup-with-zz.org @@ -144,7 +144,7 @@ We can add it to excluded packages in our .spacemacs file (within the layers sec ** better understand ii layer....bring it over to this area so i can edit it more easily. I added the contents of our layer to the reference section. The knottiest parts are our packages and funcs. I can move the config part ou8t as a package to practice that, move stephen's timetracker to a package, and then I think tackle packages and might need to pair with hh on the funcs. In the funcs is all our code around getting tmate to work in cluster and populating clipboards and all of that, and these are things that currently don't work consistently, so there will need to be some refactoring. -** [3/3] layer->packages +** layer->packages *** DONE layers CLOSED: [2020-05-03 Sun 21:11] *** DONE config @@ -771,10 +771,54 @@ I think i've lifted the most I could and put them into packages. Though the pac ** Create an ii-tools layer Sort of a misc. layer that holds useful all around tools, like find-ssh-agent and stephen's timesheet. +** TODO Create an ii-apisnoop layer +*** Create layer and readme +*** Lift apisnoop org settings into config of ii-apisnoop +*** Decide if we want an `ii/apisnoop-init` which triggers all these settings +*** Look into moving the .dir-locals functions into this layer +*** Test and celebrate ** Create an ii-mate layer *** Understand what code relates just to tmate and tmux There's a couple packages we bring in, and then some logic around setting custom sessions and such...how much of it is wrapped up in apisnoop? + After pairing with hh, I realized that near all of the code in the ii layer was moved to its own tmate package, and so is not used in this layer at all. We can clear out all the tmate code in the ii layer to make better sense of it...then build out an ii-mate layer using the tmate package as a guide. + +** Install latest version of tmate + Our commands won't work well with the version of tmate available in the ubuntu package repository, which means we need to compile from source. +*** Install libssh > 0.8.4 + This is a dependency we use in tmate that also isn't new enoughn in the standard distro repo + #+NAME: install libssh >0.8.4 + #+begin_src shell + sudo add-apt-repository ppa:kedazo/libssh-0.7.x + sudo apt-get update + sudo apt install -y libssh-dev + #+end_src +*** Gather and compile tmate from source + #+NAME: tmate from source + #+begin_src shell + sudo apt install -y \ + git \ + libtool \ + libmsgpack-dev \ + libssh-dev \ + libevent-dev \ + build-essential \ + pkg-config \ + libncurses-dev \ + zlib1g-dev + git clone -b 2.4.0 https://github.com/tmate-io/tmate.git + cd tmate + ./autogen.sh + ./configure + make + sudo make install + #+end_src + +** Improve ergonomoics of tmate +*** Check tmate version +*** Check if you are on a remote box and adjust accordingly +*** Check if in cluster +*** don't dump tmate logs to current directory * Testing things all work ** Refile Me! ** web stuff @@ -871,6 +915,11 @@ I think i've lifted the most I could and put them into packages. Though the pac async #+end_example +** tmate stuff + + #+begin_src tmate + ls + #+end_src * Reference ** The original ii layer *** packages @@ -1906,8 +1955,6 @@ I think i've lifted the most I could and put them into packages. Though the pac ) (defun ii/init-ob-tmate () (use-package ob-tmate)) - (defun ii/init-ob-powershell () - (use-package ob-powershell)) (defun ii/init-ob-tmux () (use-package ob-tmux)) (defun ii/init-iterm () @@ -1930,9 +1977,6 @@ I think i've lifted the most I could and put them into packages. Though the pac (defconst ii-packages `( - (ob-powershell - :location ,(concat (configuration-layer/get-layer-local-dir 'ii) "ob-powershell") - ) (iterm :location ,(concat (configuration-layer/get-layer-local-dir 'ii) "iterm") ) @@ -1946,215 +1990,6 @@ I think i've lifted the most I could and put them into packages. Though the pac #+end_src *** modified funcs #+begin_src elisp - ;; Stephen's weekly time tracker - (defun iso-week-to-time (year week day) - (pcase-let ((`(,m ,d ,y) - (calendar-gregorian-from-absolute - (calendar-iso-to-absolute (list week day year))))) - (encode-time 0 0 0 d m y))) - - (defun ii-timesheet () - "Create a timesheet buffer and insert skel" - (interactive) - (require 'cal-iso) - (switch-to-buffer (get-buffer-create "*ii-timesheet*")) - (ii-timesheet-skel) - ) - - (define-skeleton ii-timesheet-skel - "Prompt the week and year before generating ii timesheet for the user." - "" - (text-mode) - - ;; > "#+TITLE: Timesheet: Week " (setq v1 (skeleton-read "Timesheet Week? ")) - > "#+TITLE: Timesheet: Week " (setq v1 (skeleton-read "Timesheet Week? ")) - ;; ", " (setq v2 (skeleton-read "Timesheet Year? ")) - ", " (setq v2 "2020") - " (" (getenv "USER") ")" \n - > "#+AUTHOR: " (getenv "USER") \n - > " " \n - > "Please refer to the instructions in ii-timesheet.org as required." \n - > " " \n - > "* Week Summary" \n - > " " _ \n - > "#+BEGIN: clocktable :scope file :block thisweek :maxlevel 2 :emphasise t :tags t :formula %" \n - > "#+END" \n - > " " \n - - > "* " (format-time-string "%B %e, %Y" (iso-week-to-time (string-to-number v2) (string-to-number v1) 1)) \n - > "** Task X" \n - > "* " (format-time-string "%B %e, %Y" (iso-week-to-time (string-to-number v2) (string-to-number v1) 2)) \n - > "** Task X" \n - > "* " (format-time-string "%B %e, %Y" (iso-week-to-time (string-to-number v2) (string-to-number v1) 3)) \n - > "** Task X" \n - > "* " (format-time-string "%B %e, %Y" (iso-week-to-time (string-to-number v2) (string-to-number v1) 4)) \n - > "** Task X" \n - > "* " (format-time-string "%B %e, %Y" (iso-week-to-time (string-to-number v2) (string-to-number v1) 5)) \n - > "** Task X" \n - > " " \n - (org-mode) - (save-buffer) - ) - - ;;; This section is for tmate / copy / paste for creating/using the right eye - ;; ensure a process can run, discard output - (defun runs-and-exits-zero (program &rest args) - "Run PROGRAM with ARGS and return the exit code." - (with-temp-buffer - (if (= 0 (apply 'call-process program nil (current-buffer) nil args)) - 'true - )) - ) - - (defun xclip-working () - "Quick Check to see if X is working." - (if (getenv "DISPLAY") - ;; this xset test is a bit flakey - ;; (if (runs-and-exits-zero "xset" "q") - ;; Using xclip to set an invalid selection is as lightly intrusive - ;; check I could come up with, and not overwriting anything - ;; however it seems to hang - ;; (if (runs-and-exits-zero "xclip" "-selection" "unused") - ;; 'true) - 'true - ;; ) - ) - ) - - (defun create-target-script (filename command) - "Create a temporary script to create/connect to target tmate window" - (message "Creating a script file in tmp") - (with-current-buffer (find-file-noselect filename) - (erase-buffer) - (insert-for-yank - (concat "\n#!/bin/sh\n\n" command)) - (save-buffer) - (set-file-modes filename #o755) - ) - ) - - (defun ii/populate-clipboard-with-tmate-connect-command() - "Populate the clipboard with the correct command to connect to tmate" - (message "Trying to populate clipboard") - (let ((attach-command (if ;; incluster - (file-exists-p "/var/run/secrets/kubernetes.io/serviceaccount/namespace") - ;; use kubectl - (concat "kubectl exec -n " - (with-temp-buffer - (insert-file-contents - "/var/run/secrets/kubernetes.io/serviceaccount/namespace") - (buffer-string)) - " -ti " system-name - " attach " (file-name-base load-file-name)) - ;; out of cluster, use tmate directly - (concat "tmate -S " socket " attach")) - )) - (gui-select-text attach-command) - (osc52-interprogram-cut-function attach-command) - ) - ) - (defun populate-terminal-clipboard () - "Populate the osc52 clipboard via terminal with the start-tmate-sh" - ;; TODO - (message "Unable to set X Clipboard to contain the start-tmate-sh") - ;; (create-target-script tmate-sh start-tmate-command) - ;; (gui-select-text tmate-sh) - (if (string= (getenv "KUBERNETES_PORT_443_TCP_PROTO") "tcp") - (setq current-tmate-sh (concat "kubectl exec -ti " system-name " attach " (file-name-base load-file-name))) - (progn - (setq current-tmate-sh tmate-sh) ;; since tmate-sh is buffer-local.. - (if (string= (getenv "CLOUD_SHELL") "true") - (setq current-tmate-ssh (concat "gcloud alpha cloud-shell ssh --ssh-flag=-t --command=" tmate-sh)) - (if (string= system-name "sharing.io") - (setq current-tmate-ssh (concat "ssh -tAX " ssh-user-host " " tmate-sh)) - (setq current-tmate-ssh tmate-sh) - ) - ) - ) - ) - (if (string= (getenv "KUBERNETES_PORT_443_TCP_PROTO") "tcp") - (setq current-tmate-ssh (concat "kubectl exec -ti " system-name " attach " (file-name-base load-file-name))) - (if (string= (getenv "CLOUD_SHELL") "true") - (setq current-tmate-ssh (concat "gcloud alpha cloud-shell ssh --ssh-flag=-t --command=" tmate-sh)) - (if (string= system-name "sharing.io") - (setq current-tmate-ssh (concat "ssh -tAX " ssh-user-host " " tmate-sh)) - (setq current-tmate-ssh tmate-sh)) - ) - ) - (message "Trying to set via osc52") - (osc52-interprogram-cut-function current-tmate-ssh) - (with-current-buffer (get-buffer-create "start-tmate-sh" ) - (erase-buffer) - (insert-for-yank "You may need to copy this manually:\n\n" ) - (if (string= (getenv "KUBERNETES_PORT_443_TCP_PROTO") "tcp") - (insert-for-yank (concat "\nConnect to this in cluster tmate via:\n\n" current-tmate-sh)) - (insert-for-yank - (concat "\nTo open on another host, forward your iisocket by pasting:\n\n" current-tmate-ssh - "\n\nOR open another terminal on the same host and paste:\n\n" current-tmate-sh) - ) - ) - ) - ) - (defun populate-x-clipboard () - "Populate the X clipboard with the start-tmate-sh" - (message "Setting X Clipboard to contain the start-tmate-sh") - (xclip-mode 1) - (create-target-script tmate-sh start-tmate-command) - (setq current-tmate-sh tmate-sh) ;; since tmate-sh is buffer-local.. - (setq current-tmate-ssh (concat "ssh -tAX " ssh-user-host " " tmate-sh)) - (if (string= ssh-host "") - (progn - (gui-select-text current-tmate-sh) - (with-current-buffer (get-buffer-create "start-tmate-sh") - (insert-for-yank "The following has been populated to your local X clipboard:\n") - (insert-for-yank - ;; we can use the global current-tmate-sh - (concat "Open another terminal on the same host and paste:\n\n" current-tmate-sh) - )) - ) - (progn - (gui-select-text current-tmate-ssh) - (with-current-buffer (get-buffer-create "start-tmate-ssh") - (insert-for-yank "The following has been populated to your local X clipboard:\n") - (insert-for-yank - ;; we can use the global current-tmate-sh - (concat "Open another terminal on the your emacs host and paste:\n\n" current-tmate-ssh) - )) - ) - ) - (xclip-mode 0) - ;; and unset it when done - (setq current-tmate-ssh nil) - (setq current-tmate-sh nil)) - - (defun ssh-find-agent () - (interactive) - (setenv "SSH_AUTH_SOCK" (shell-command-to-string "find /tmp /run/host/tmp/ -type s -regex '.*/ssh-.*/agent..*$' 2> /dev/null | tail -n 1 | tr -d '\n'")) - (message (getenv "SSH_AUTH_SOCK")) - ) - (with-eval-after-load "org" - ;; (add-to-list 'org-src-lang-modes '("go-mode" . sql)) - (add-to-list 'org-structure-template-alist - `("g" . "src go"))) - - ;; This section is for setting org code block defaults that are based on the current user and file - ;; alist-set is used to override the existing settings - (defun alist-set (key val alist &optional symbol) - "Set property KEY to VAL in ALIST. Return new alist. - This creates the association if it is missing, and otherwise sets - the cdr of the first matching association in the list. It does - not create duplicate associations. By default, key comparison is - done with `equal'. However, if SYMBOL is non-nil, then `eq' is - used instead. - - This method may mutate the original alist, but you still need to - use the return value of this method instead of the original - alist, to ensure correct results." - (if-let ((pair (if symbol (assq key alist) (assoc key alist)))) - (setcdr pair val) - (push (cons key val) alist)) - alist) - ;; Some local variable defaults that set our database connections ;; note the UID being dynamic, so we can have a dedicated port per person (defun ii/sql-org-hacks() @@ -2227,8 +2062,8 @@ I think i've lifted the most I could and put them into packages. Though the pac #'ii/advice:org-babel-execute-src-block) (funcall obde) (advice-add 'org-babel-execute-src-block - :before #'ii/advice:org-babel-execute-src-block) - ) + :before #'ii/advice:org-babel-execute-src-block)) + (defun ii/advice:org-babel-execute-src-block (&optional arg info params) "if ii-mate not set and this is a tmate src block" (interactive) @@ -2238,7 +2073,6 @@ I think i've lifted the most I could and put them into packages. Though the pac (org-session (alist-get :session (nth 2 (org-babel-get-src-block-info t)))) (socket (alist-get :socket (nth 2 (org-babel-get-src-block-info t)))) (session-dir (cdr (assq :dir params))) - ;; (session-x (message "terminal: %S, socket: %S, org-session: %S" terminal socket org-session)) (session-name (ob-tmate--tmate-session org-session)) (session-window (ob-tmate--tmate-window org-session)) (session-socket (if socket @@ -2265,8 +2099,7 @@ I think i've lifted the most I could and put them into packages. Though the pac " -s " session-name " -n " "init"; session-window " -c " session-dir - "read X") - )))))))) + "read X"))))))))) ;; This is the function intended to be run as a before-hack-local-variables-hook (defun ii/before-local-var-hacks() From e65e182391f301bbd5be541f1c9eb6a94326a85e Mon Sep 17 00:00:00 2001 From: zach mandeville Date: Fri, 8 May 2020 04:21:03 +0000 Subject: [PATCH 05/13] add some checks for tmate and whether they are remote --- layers/ii-mate/local/ob-tmate/ob-tmate.el | 142 +++++++++------------- 1 file changed, 57 insertions(+), 85 deletions(-) diff --git a/layers/ii-mate/local/ob-tmate/ob-tmate.el b/layers/ii-mate/local/ob-tmate/ob-tmate.el index e28049d..7bbc9c1 100644 --- a/layers/ii-mate/local/ob-tmate/ob-tmate.el +++ b/layers/ii-mate/local/ob-tmate/ob-tmate.el @@ -43,6 +43,7 @@ (require 'seq) (require 'osc52e) (require 'iterm) +(require 's) (defcustom org-babel-tmate-location "tmate" "The command location for tmate. @@ -82,68 +83,81 @@ Change in case you want to use a different tmate than the one in your $PATH." (:session . "tmate") (:window . "i") (:dir . ".") - (:socket . nil) - ) + (:socket . nil)) "Default arguments to use when running tmate source blocks.") (add-to-list 'org-src-lang-modes '("tmate" . sh)) +;;;; +;; helper functions +;;;; + +(defun tmate-compatability-check () + (let* ((tmate-version (shell-command-to-string "tmate -V")) + (tmate-not-installed-p (s-contains? "command not found" tmate-version)) + (compatible-version-p (s-matches? "tmate [2-9].[4-9].[0-9]" tmate-version))) + (cond + (tmate-not-installed-p "not installed") + ((eq nil compatible-version-p) "not compatible") + (t "compatible")))) + +(defvar install-tmate "It looks like you don't have tmate installed. You will want to install tmate 2.4.0, available on its github releases page.") +(defvar upgrade-tmate "It looks like you're using an earlier tmate. We require version 2.4.0 or above. You can find it on their github releases page.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; org-babel interface ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (defun org-babel-execute:tmate (body params) + "Check tmate compatability. If compatible, sends the body and params on to our tmate functions. Otherwise sends message explaining requirements." + (message "Checking for compatible tmate before continuing") + (save-window-excursion + (let* ((tmate-compatability (tmate-compatability-check))) + (cond + ((eq tmate-compatability "not installed")(message install-tmate)) + ((eq tmate-compatability "not compatible")(message upgrade-tmate)) + (t (send-src-to-tmate body params)))))) + +(defun send-src-to-tmate (body params) "Send a block of code via tmate to a terminal using Babel. \"default\" session is used when none is specified. Argument BODY the body of the tmate code block. Argument PARAMS the org parameters of the code block." (message "Sending source code block to interactive terminal session...") (save-window-excursion - (let* ( - (socket (cdr (assq :socket params))) + (let* ((session (cdr (assq :session params))) + (socket (ob-tmate--tmate-socket session)) (dir (cdr (assq :dir params))) - (session (cdr (assq :session params))) (window (cdr (assq :window params))) - (socket (if socket - (expand-file-name socket) - (ob-tmate--tmate-socket session) - )) - ;; (tmate-command (concat org-babel-tmate-location " -S " socket - ;; " attach-session || read X") (ob-session (ob-tmate--create :session session :window window :socket socket)) + (on-remote-p (stringp (getenv "SSH_CONNECTION"))) (session-alive (ob-tmate--session-alive-p ob-session)) (window-alive (ob-tmate--window-alive-p ob-session))) - ;; Create tmate session and window if they do not yet exist - ;; Start terminal window if the session does not yet exist (message "OB-TMATE: Checking for session: %S" session-alive) (unless session-alive (progn (message "OB-TMATE: create-session") (ob-tmate--create-session session dir socket) (ob-tmate--start-terminal-window ob-session) + (if on-remote-p + (progn + (y-or-n-p "it looks like you are remote. an attach command was copied to your clipboard. Paste it in a new terminal on this same remote machine.") + (osc52-interprogram-cut-function (concat "tmate -S " socket " attach"))) (y-or-n-p "Has a terminal started and shown you a url?") (gui-select-text (ob-tmate--ssh-url ob-session)) (osc52-interprogram-cut-function (concat (ob-tmate--ssh-url ob-session) " # " (ob-tmate--web-url ob-session))) (if (y-or-n-p "Open browser for url?") - (browse-url (ob-tmate--web-url ob-session)) - ) - ) - ) + (browse-url (ob-tmate--web-url ob-session)))))) (message "OB-TMATE: Checking for window: %S" window-alive) (unless window-alive - (progn - (message "OB-TMATE: create-window")) - (ob-tmate--create-window ob-session dir) + (message "OB-TMATE: create-window") + (ob-tmate--create-window ob-session dir)) ;; (while (not (ob-tmate--window-alive-p ob-session))) - ) ;; Wait until tmate window is available ;; Disable window renaming from within tmate ;; (ob-tmate--disable-renaming ob-session) (ob-tmate--send-body ob-session (org-babel-expand-body:generic body params))))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ob-tmate object ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -164,17 +178,13 @@ Argument PARAMS the org parameters of the code block." (if (string-equal "" window) nil window))) (defun ob-tmate--tmate-socket (org-session) "Extract tmate window from ORG-SESSION string." - (let* ( - (session-name (car (split-string org-session ":"))) - ) - (concat temporary-file-directory user-login-name "." session-name ".tmate" ) - )) + (let* ((session-name (car (split-string org-session ":")))) + (concat temporary-file-directory user-login-name "." session-name ".tmate" ))) (defun ob-tmate--from-session-window-socket (session window socket) "Create a new ob-tmate-session object from ORG-SESSION specification. Required argument SOCKET: the location of the tmate socket." - (ob-tmate--create :session session :window window :socket socket) - ) + (ob-tmate--create :session session :window window :socket socket)) (defun ob-tmate--window-default (ob-session) "Extracts the tmate window from the ob-tmate- object. @@ -217,16 +227,13 @@ Optional command-line arguments can be passed in ARGS." (apply 'start-process "ob-tmate" "*Messages*" org-babel-tmate-location "-S" (ob-tmate--socket ob-session) - args) - ) + args)) (progn (message (concat "OB-TMATE: execute args: => " (string-join args " "))) - ;; (message (concat "OB-TMATE: execute ob-session: => " ob-session)) (message (concat "OB-TMATE: execute start-process:" (ob-tmate--socket ob-session))) (setenv "TMUX") (apply 'start-process - "ob-tmate" "*Messages*" org-babel-tmate-location args))) - ) + "ob-tmate" "*Messages*" org-babel-tmate-location args)))) (defun ob-tmate--execute-string (ob-session &rest args) "Execute a tmate command with arguments as given. @@ -244,8 +251,7 @@ automatically space separated." (defun ob-tmate--start-terminal-window-iterm (ob-session) "Start a terminal window in iterm" - (let* ((socket (ob-tmate--socket ob-session)) - ) + (let* ((socket (ob-tmate--socket ob-session))) (iterm-new-window-send-string (concat "tmate " @@ -267,18 +273,15 @@ automatically space separated." "-e" (concat org-babel-tmate-location " -S " socket " attach-session || read X") - ) - ) - ) + ))) + (defun ob-tmate--start-terminal-window-osc52 (ob-session) "Start a terminal window in iterm" (let* ((socket (ob-tmate--socket ob-session)) (tmate-command (concat org-babel-tmate-location " -S " socket - " attach-session || read X") - ) - (osc52-interprogram-cut-function tmate-command) - ) - )) + " attach-session || read X")) + (osc52-interprogram-cut-function tmate-command)))) + (defun ob-tmate--start-terminal-window (ob-session) "Start a TERMINAL window with tmate attached to session. @@ -289,9 +292,7 @@ Argument OB-SESSION: the current ob-tmate session." ((string= org-babel-tmate-terminal "xterm") (ob-tmate--start-terminal-window-xterm ob-session)) ((string= org-babel-tmate-terminal "osc52") (ob-tmate--start-terminal-window-osc52 ob-session)) ((string= org-babel-tmate-terminal "web") (ob-tmate--start-terminal-window-osc52 ob-session)) - (t (message "We didn't find a supported terminal type")) - ) - ) + (t (message "We didn't find a supported terminal type")))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Tmate interaction @@ -348,8 +349,7 @@ Argument OB-SESSION: the current ob-tmate session." " && " "read X" ; need to hit enter to continue "\"" ; end command - ) - ) + )) ;;;;;; INSTALL tmate hook for when a client attaches ;; Wait for tmate to be ready ;; This means tmate ssh/web urls are handy @@ -359,26 +359,6 @@ Argument OB-SESSION: the current ob-tmate session." ;; When new client-attaches, create new window and run osc52-tmate.sh ;; tmux set-environment -g PATH "" ;; tmate -S $TMATE_SOCKET set-hook -g client-attached 'run-shell "tmate new-window osc52-tmate.sh"' - - ;; (ob-tmate--execute ob-session - ;; "new-session" - ;; ;; "-A" ;; attach if it already exists (d) - ;; "-d" ;; just create the session, don't attach. - ;; ;; "-S" (ob-tmate--socket ob-session) - ;; ;; "-S" "/tmp/ob-tmate-socket" ;; Static for now - ;; ;; "-u" ;; UTF-8 please... only in newer tmux - ;; ;; "-vv" ;; Logs please... also only in newer tmux - ;; "-c" (expand-file-name session-dir) - ;; "-s" (ob-tmate--session ob-session) - ;; "-n" (ob-tmate--window-default ob-session) - ;; ) - ;; (message "OB-TMATE: Waiting for tmate to be ready") - ;; (ob-tmate--execute ob-session "wait" "tmate-ready") - ;; how can we capture this? - ;; (setq ob-tmate-ssh-string (ob-tmate--execute-string ob-session - ;; "display" "-p" "#{tmate_ssh}" - ;; )) - ;; (message (concat "OB-TMATE: " ob-tmate-ssh-string)) ) @@ -428,12 +408,10 @@ Argument OB-SESSION: the current ob-tmate session." "select-window" "-t" (ob-tmate--window-default ob-session)) (ob-tmate--execute ob-session - ;; "-S" (ob-tmate--socket ob-session) "send-keys" "-l" "-t" (ob-tmate--window-default ob-session) - line "\n") - ))) + line "\n")))) (defun ob-tmate--send-body (ob-session body) "If tmate window (passed in OB-SESSION) exists, send BODY to it. @@ -469,22 +447,19 @@ Argument OB-SESSION: the current ob-tmate session." ;; if we can 'tmate ls' and return zero, we are good (= 0 (apply 'call-process org-babel-tmate-location nil nil nil "-S" (ob-tmate--socket ob-session) - '("ls")) - )) + '("ls")))) (defun ob-tmate--ssh-url (ob-session) "Retrieve the ssh # http://url/session for the ob-session" (ob-tmate--execute-string ob-session "display" - "-p '#{tmate_ssh}'" - )) + "-p '#{tmate_ssh}'")) + (defun ob-tmate--web-url (ob-session) "Retrieve the ssh # http://url/session for the ob-session" (substring (ob-tmate--execute-string ob-session "display" - "-p '#{tmate_web}'" - ) - 0 -1)) + "-p '#{tmate_web}'") 0 -1)) (defun ob-tmate--window-alive-p (ob-session) "Check if WINDOW exists in tmate session. @@ -497,12 +472,9 @@ If no window is specified in OB-SESSION, returns 't." (output (ob-tmate--execute-string ob-session "list-windows" "-F '#W'" - )) - ) + ))) ;; (y-or-n-p (concat "Is {" target "} alive?")) - (string-match-p (concat window "\n") output) - ) - ) + (string-match-p (concat window "\n") output))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test functions From 12624c3ba3dde91069a0d5f92831e6b77c82a3ec Mon Sep 17 00:00:00 2001 From: zach mandeville Date: Fri, 8 May 2020 04:30:23 +0000 Subject: [PATCH 06/13] write up async initial thoughts in work diary --- org/setup-with-zz.org | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/org/setup-with-zz.org b/org/setup-with-zz.org index fff7ed7..4f78323 100644 --- a/org/setup-with-zz.org +++ b/org/setup-with-zz.org @@ -815,10 +815,23 @@ I think i've lifted the most I could and put them into packages. Though the pac #+end_src ** Improve ergonomoics of tmate -*** Check tmate version -*** Check if you are on a remote box and adjust accordingly -*** Check if in cluster +*** DONE Check tmate version + CLOSED: [2020-05-08 Fri 04:22] +*** DONE Check if you are on a remote box and adjust accordingly + CLOSED: [2020-05-08 Fri 04:22] +*** TODO Get values from tmate without requiring y-or-n prompts + We have these prompts that basically give us a few seconds of room for the tmate sessiont o complete...so we have a "do you have a terminal window?" which is intended to pause the process so that tmate has some time to run...no matter what someone presses, it'll copy the tmate info to their clipboard once they've pressed it. + + I am now doing the same for the remote side, and it just feels clunky. This feels like a repeated enough pattern in our function that havin it be more logical might make it easier to maintain. + + I started to research two async libraries: + - https://github.com/chuntaro/emacs-async-await + - https://github.com/skeeto/emacs-aio + + both use similar syntax to javascript (so i feel comfy) and are small enough. I think I like chuntaro's library more. In gboth, i couldn't quite tell if i had to write a promise or if i could just have something that was going to take a minyute...in other words, whether the ob-tmate-- functions would work to just slot in to a (aio-wait-for tmate_ssh) type command...did some scratch work, but it was a bit hard to simulate. Will try for another half hour or os and see if it's a pth i wanna go down. + *** don't dump tmate logs to current directory +*** * Testing things all work ** Refile Me! ** web stuff From c9bed04e4887e43a4b13faee978c2282c52eb069 Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Tue, 12 May 2020 17:34:35 +0000 Subject: [PATCH 07/13] Adding ii-yaml layer Co-Authored-By: Robert Kielty Co-Authored-By: Berno Kleinhans --- init.el | 3 +- .../local/flycheck-swagger-tools/LICENSE | 674 ++++++++++++++++++ .../local/flycheck-swagger-tools/README.md | 21 + .../flycheck-swagger-tools.el | 94 +++ .../ii-yaml/local/openapi-yaml-mode/LICENSE | 674 ++++++++++++++++++ .../ii-yaml/local/openapi-yaml-mode/README.md | 30 + .../examples/markdown-tables.yaml | 21 + .../openapi-yaml-mode/openapi-yaml-mode.el | 559 +++++++++++++++ layers/ii-yaml/packages.el | 73 ++ 9 files changed, 2148 insertions(+), 1 deletion(-) create mode 100644 layers/ii-yaml/local/flycheck-swagger-tools/LICENSE create mode 100644 layers/ii-yaml/local/flycheck-swagger-tools/README.md create mode 100644 layers/ii-yaml/local/flycheck-swagger-tools/flycheck-swagger-tools.el create mode 100644 layers/ii-yaml/local/openapi-yaml-mode/LICENSE create mode 100644 layers/ii-yaml/local/openapi-yaml-mode/README.md create mode 100644 layers/ii-yaml/local/openapi-yaml-mode/examples/markdown-tables.yaml create mode 100644 layers/ii-yaml/local/openapi-yaml-mode/openapi-yaml-mode.el create mode 100644 layers/ii-yaml/packages.el diff --git a/init.el b/init.el index 00c39a3..de5d227 100644 --- a/init.el +++ b/init.el @@ -32,7 +32,7 @@ This function should only modify configuration layer settings." ;; List of configuration layers to load. dotspacemacs-configuration-layers - '( + '(yaml ;; ---------------------------------------------------------------- ;; Example of useful layers you may want to use right away. ;; Uncomment some layer names and press `SPC f e R' (Vim style) or @@ -64,6 +64,7 @@ This function should only modify configuration layer settings." ii-org-capture ii-sql ii-tools + ii-yaml ) ;; List of additional packages that will be installed without being diff --git a/layers/ii-yaml/local/flycheck-swagger-tools/LICENSE b/layers/ii-yaml/local/flycheck-swagger-tools/LICENSE new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/layers/ii-yaml/local/flycheck-swagger-tools/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/layers/ii-yaml/local/flycheck-swagger-tools/README.md b/layers/ii-yaml/local/flycheck-swagger-tools/README.md new file mode 100644 index 0000000..c31bd76 --- /dev/null +++ b/layers/ii-yaml/local/flycheck-swagger-tools/README.md @@ -0,0 +1,21 @@ +# flycheck-swagger-tools + +An Emacs Flycheck checker for Swagger YAML and JSON files that uses [swagger-tools](https://github.com/apigee-127/swagger-tools). + +flycheck-swagger-tools is still under initial development and might not be stable. + +## Configuration + +[swagger-tools](https://github.com/apigee-127/swagger-tools) must be installed. + +``` shell +npm install -g swagger-tools +``` + +The checker can be activating by requiring this package. + +``` emacs-lisp +(require 'flycheck-swagger-tools) +``` + +By default, only the first 4000 characters of a file are scanned to find the swagger 2.0 element. To avoid stack overflow in Emacs multi-line regex, this limit is necessary. The defcustom swagger-tools-predicate-regexp-match-limit can be used to change the limit. That could be necessary for YAML files with long initial comments. diff --git a/layers/ii-yaml/local/flycheck-swagger-tools/flycheck-swagger-tools.el b/layers/ii-yaml/local/flycheck-swagger-tools/flycheck-swagger-tools.el new file mode 100644 index 0000000..4c04c2a --- /dev/null +++ b/layers/ii-yaml/local/flycheck-swagger-tools/flycheck-swagger-tools.el @@ -0,0 +1,94 @@ +;;; flycheck-swagger-tools.el --- Flycheck checker for swagger-tools. + +;; Copyright (C) 2017-2018 Marc-André Goyette +;; Author: Marc-André Goyette +;; URL: https://github.com/magoyette/flycheck-swagger-tools +;; Version: 0.1.0 +;; Package-Requires: ((emacs "25")) +;; Keywords: languages + +;; 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. + +;; For a full copy of the GNU General Public License +;; see . + +;;; Commentary: + +;; flycheck-swagger-tools provides a Flycheck checker for swagger-tools. +;; This allows to validate Swagger YAML and JSON files. + +;; The checker can be activating by requiring this package. + +;; (require 'flycheck-swagger-tools) + +;; By default, only the first 4000 characters of a file are scanned to +;; find the swagger 2.0 element. To avoid stack overflow in Emacs +;; multi-line regex, this value is necessary. The defcustom +;; swagger-tools-predicate-regexp-match-limit can be used to change this +;; limit. That could be necessary for YAML files with long initial comments. + +;;; Code: + +(require 'flycheck) + +(defgroup swagger-tools nil + "Validate swagger files with swagger-tools." + :group 'swagger + :prefix "swagger-tools-") + +(defcustom swagger-tools-predicate-regexp-match-limit 4000 + "Defines the number of characters that will be scanned at the beginning of a +buffer to find the swagger 2.0 element." + :type 'integer + :group 'swagger-tools) + +;;;###autoload +(flycheck-define-checker swagger-tools + "A checker that uses swagger tools to validate Swagger2 JSON and YAML files. +See URL `https://github.com/apigee-127/swagger-tools'." + :command ("swagger-tools" "validate" source) + :predicate + (lambda () + (string-match + "\\(.\\|\n\\)*\\([[:space:]]\\|\"\\|\\'\\)*swagger\\([[:space:]]\\|\"\\|\\'\\)*:[[:space:]]*[\"\\']2.0[\"\\'].*" + ;; Need to avoid stack overflow for multi-line regex + (buffer-substring 1 (min (buffer-size) + swagger-tools-predicate-regexp-match-limit)))) + :error-patterns + ((warning line-start " " (message (one-or-more not-newline) + "is not used" + (one-or-more not-newline)) + line-end) + ;; js-yaml error with position + (error line-start " error: " (message) " at line " line ", column " column ":" line-end) + ;; js-yaml error without position + (error line-start " error: " (message) ": " (one-or-more not-newline) line-end) + ;; swagger-tools error (always contain a # symbol in the message) + (error line-start + " " + (message (optional (one-or-more not-newline)) + (one-or-more "#") + (one-or-more not-newline)) + line-end)) + :error-filter + ;; Add line number 1 if the error has no line number + (lambda (errors) + (let ((errors (flycheck-sanitize-errors errors))) + (dolist (err errors) + (unless (flycheck-error-line err) + (setf (flycheck-error-line err) 1))) + errors)) + :modes (json-mode openapi-yaml-mode yaml-mode)) + +(add-to-list 'flycheck-checkers 'swagger-tools) + +(provide 'flycheck-swagger-tools) +;;; flycheck-swagger-tools.el ends here diff --git a/layers/ii-yaml/local/openapi-yaml-mode/LICENSE b/layers/ii-yaml/local/openapi-yaml-mode/LICENSE new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/layers/ii-yaml/local/openapi-yaml-mode/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/layers/ii-yaml/local/openapi-yaml-mode/README.md b/layers/ii-yaml/local/openapi-yaml-mode/README.md new file mode 100644 index 0000000..1625ba5 --- /dev/null +++ b/layers/ii-yaml/local/openapi-yaml-mode/README.md @@ -0,0 +1,30 @@ +# OpenAPI YAML Mode + +An Emacs major mode for [OpenAPI](https://github.com/OAI/OpenAPI-Specification) YAML files. OpenAPI YAML mode supports OpenAPI 2 and 3. OpenAPI 2 files are identical to the [Swagger](https://swagger.io/) 2 files. + +OpenAPI YAML mode is based on [yaml-mode](https://github.com/yoshiki/yaml-mode), but uses a different strategy for syntax highlight that takes into consideration the OpenAPI specification. + +OpenAPI YAML mode is under initial development and is not yet stable. + +## Features + +- Syntax highlight based on the OpenAPI specification (version 2 and 3). +- Basic completion with `completion-at-point`. Works with [Company](https://company-mode.github.io/) through the CAPF back-end. +- [IMenu](https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html) + for paths and operationIds. + +## Complementary packages + +- Swagger 2 validation can be added with [flycheck-swagger-cli](https://github.com/magoyette/flycheck-swagger-cli) or [flycheck-swagger-tools](https://github.com/magoyette/flycheck-swagger-tools). + +## Customizations + +### Use the yaml-mode syntax highlight + +The defcustom variable `openapi-yaml-use-yaml-mode-syntax-highlight` can be used to +disable the OpenAPI syntax highlight of OpenAPI YAML Mode. The default syntax +highlight of [yaml-mode](https://github.com/yoshiki/yaml-mode) is used instead. + +``` emacs-lisp +(setq openapi-yaml-use-yaml-mode-syntax-highlight t) +``` diff --git a/layers/ii-yaml/local/openapi-yaml-mode/examples/markdown-tables.yaml b/layers/ii-yaml/local/openapi-yaml-mode/examples/markdown-tables.yaml new file mode 100644 index 0000000..95f43d6 --- /dev/null +++ b/layers/ii-yaml/local/openapi-yaml-mode/examples/markdown-tables.yaml @@ -0,0 +1,21 @@ +swagger: '2.0' +info: + description: | + Examples of Markdown tables. + + First header | Second header + -------------|-------------- + Cell #1 | Cell #2 + + | First header | Second header | + | ------------ | ------------- | + | Cell #1 | Cell #2 | + + First header | Second header + ------------ | ------------- + Cell #1 | Cell #2 + + | Single column table | + | ------------------- | + | Cell #1 | + | Cell #2 | diff --git a/layers/ii-yaml/local/openapi-yaml-mode/openapi-yaml-mode.el b/layers/ii-yaml/local/openapi-yaml-mode/openapi-yaml-mode.el new file mode 100644 index 0000000..9c782e8 --- /dev/null +++ b/layers/ii-yaml/local/openapi-yaml-mode/openapi-yaml-mode.el @@ -0,0 +1,559 @@ +;;; openapi-yaml-mode.el --- Major mode for OpenAPI YAML files. + +;; Copyright (C) 2017-2018 Marc-André Goyette +;; Author: Marc-André Goyette +;; URL: https://github.com/magoyette/openapi-yaml-mode +;; Version: 0.1.0 +;; Package-Requires: ((emacs "25")) +;; Keywords: languages + +;; 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. + +;; For a full copy of the GNU General Public License +;; see . + +;;; Commentary: + +;; An Emacs major mode for OpenAPI YAML files. OpenAPI YAML mode supports +;; OpenAPI 2 and 3. OpenAPI 2 files are identical to the Swagger 2 files. + +;; OpenAPI YAML mode is based on yaml-mode, but uses a different strategy +;; for syntax highlight that takes into consideration the OpenAPI specification. + +;; OpenAPI YAML mode is under initial development and is not yet stable. + +;; Features: + +;; - Syntax highlight based on the OpenAPI specification (version 2 and 3). +;; - Basic completion with `completion-at-point`. Works with Company +;; through the CAPF back-end. +;; - IMenu for paths and operationIds. + +;; Customizations: + +;; The defcustom variable openapi-yaml-use-yaml-mode-syntax-highlight can be +;; used to disable the OpenAPI syntax highlight of OpenAPI YAML Mode. +;; The default syntax highlight of yaml-mode is used instead. + +;; (setq openapi-yaml-use-yaml-mode-syntax-highlight t) + +;;; Code: + +(require 'font-lock) +(require 'yaml-mode) + +(defgroup openapi-yaml nil + "OpenAPI YAML files." + :group 'openapi + :prefix "openapi-yaml-") + +(defcustom openapi-yaml-predicate-regexp-match-limit 4000 + "Number of characters to scan to find the OpenApi/Swagger element." + :type 'integer + :group 'openapi-yaml) + +(defcustom openapi-yaml-use-yaml-mode-syntax-highlight nil + "If true, openapi-yaml-mode will use the regular syntax highlight of yaml-mode." + :type 'boolean + :group 'openapi-yaml) + +(defconst openapi-yaml-mode--syntax-table + (let ((table (make-syntax-table))) + + (modify-syntax-entry ?' "." table) + + (modify-syntax-entry ?\" "." table) + + (set (make-local-variable 'indent-line-function) 'yaml-indent-line) + (set (make-local-variable 'indent-tabs-mode) nil) + (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph) + + table)) + +;; Source : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md +(defconst openapi-yaml-mode--openapi-keywords + '(;; Literals + "true" + "false" + ;; Mime Types + "application/json" + "application/x-www-form-urlencoded" + "application/xml" + "multipart/form-data" + "text/plain" + ;; Types + "integer" + "number" + "string" + "boolean" + ;; Formats + "int32" + "int64" + "float" + "double" + "byte" + "binary" + "date" + "date-time" + "password" + ;; Additional Types + "array" + ;; JSON Schema + "title" + "multipleOf" + "maximum" + "exclusiveMaximum" + "minimum" + "exclusiveMinimum" + "maxLength" + "minLength" + "pattern" + "maxItems" + "minItems" + "uniqueItems" + "maxProperties" + "minProperties" + "required" + "enum" + "type" + "allOf" + "items" + "properties" + "additionalProperties" + "description" + "format" + "default" + ;; Common to many objects + "$ref" + "deprecated" + "example" + "examples" + "externalDocs" + "headers" + "in" + "name" + "operationId" + "parameters" + "responses" + "schema" + "security" + "tags" + "url" + ;; Schema fields + "info" + "paths" + ;; Info object + "title" + "termsOfService" + "contact" + "license" + "version" + ;; Contact object + "email" + ;; Path Item fields + "get" + "put" + "post" + "delete" + "options" + "head" + "patch" + ;; Path Item or Operation fields + "summary" + ;; Parameter object + "allowEmptyValue" + ;; Swagger allowed values for an in field + "query" + "header" + "path" + ;; Schema object fields + "discriminator" + "readOnly" + "xml" + ;; XML object + "namespace" + "prefix" + "attribute" + "wrapped" + ;; Security Scheme or OAuth Flow fields + "authorizationUrl" + "tokenUrl" + "scopes" + )) + +;; Source : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md +(defconst openapi-yaml-mode--openapi2-keywords + (append openapi-yaml-mode--openapi-keywords + '(;; Additional Types + "file" + ;; Schema fields + "swagger" + "host" + "basePath" + "definitions" + "parameters" + "securityDefinitions" + ;; Swagger allowed values for an in field + "formData" + "body" + ;; Security Scheme object + "flow" + + ;;;;; TO VERIFY + ;; Common to many objects + "collectionFormat" + "consumes" + "produces" + "scheme" + ;; Swagger allowed values for a schemes field + "http" + "https" + "ws" + "wss" + ;; Swagger allowed values for an collectionFormat field + "csv" + "ssv" + "tsv" + "pipes" + "multi" + ;; Swagger allowed values for a type field + "basic" + "apiKey" + "oauth2" + ;; Swagger allowed values for a flow field + "implicit" + "password" + "application" + "accessCode" + ))) + +;; Source : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md +(defconst openapi-yaml-mode--openapi3-keywords + (append openapi-yaml-mode--openapi-keywords + '(;; JSON Schema + "oneOf" + "anyOf" + "not" + ;; Common to many objects + "allowReserved" + "callbacks" + "content" + "explode" + "links" + "requestBody" + "servers" + "style" + ;; Schema fields + "openapi" + "components" + ;; Server fields + "variables" + ;; Components fields + "schemas" + "requestBodies" + "securitySchemes" + ;; Path Item fields + "trace" + ;; Swagger allowed values for an in field + "cookie" + ;; Style values + "matrix" + "label" + "form" + "simple" + "spaceDelimited" + "pipeDelimited" + "deepObject" + ;; Media Type fields + "encoding" + ;; Encoding fields + "contentType" + ;; Example fields + "value" + "externalValue" + ;; Link fields + "operationRef" + "server" + ;; Schema object fields + "nullable" + "writeOnly" + ;; Discriminator fields + "propertyName" + "mapping" + ;; Security Scheme fields + "bearerFormat" + "flows" + "openIdConnectUrl" + ;; OAuth Flows fields + "implicit" + "password" + "clientCredentials" + "authorizationCode" + ;; OAuth Flow fields + "refreshUrl" + ))) + +(defun openapi-yaml-mode--openapi2-completion-at-point () + "Completion function for Open API 2 files." + (let ((bounds (bounds-of-thing-at-point 'word))) + (when bounds + (list (car bounds) + (cdr bounds) + openapi-yaml-mode--openapi2-keywords)))) + +(defun openapi-yaml-mode--openapi3-completion-at-point () + "Completion function for Open API 3 files." + (let ((bounds (bounds-of-thing-at-point 'word))) + (when bounds + (list (car bounds) + (cdr bounds) + openapi-yaml-mode--openapi3-keywords)))) + +(defvar openapi-yaml-markdown-header-face 'openapi-yaml-markdown-header-face + "Face for Markdown headers in an OpenAPI YAML file.") + +(defface openapi-yaml-markdown-header-face + '((t (:inherit font-lock-type-face :weight bold))) + "Face for Markdown headers in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-markdown-table-bold-face 'openapi-yaml-markdown-table-bold-face + "Face for Markdown bold text in an OpenAPI YAML file.") + +(defface openapi-yaml-markdown-table-bold-face + '((t (:inherit font-lock-comment-face :weight bold))) + "Face for Markdown bold text in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-markdown-italic-face 'openapi-yaml-markdown-italic-face + "Face for Markdown italic text in an OpenAPI YAML file.") + +(defface openapi-yaml-markdown-italic-face + '((t (:slant italic))) + "Face for Markdown italic text in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-http-code-face 'openapi-yaml-http-code-face + "Face for a HTTP code in an OpenAPI YAML file.") + +(defface openapi-yaml-http-code-face + '((t (:inherit font-lock-constant-face :weight bold))) + "Face for a HTTP code in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-http-method-face 'openapi-yaml-http-method-face + "Face for a HTTP method name in an OpenAPI YAML file.") + +(defface openapi-yaml-http-method-face + '((t (:inherit font-lock-constant-face :weight bold))) + "Face for a HTTP method name in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-url-path-face 'openapi-yaml-url-path-face + "Face for an URL path in an OpenAPI YAML file.") + +(defface openapi-yaml-url-path-face + '((t (:inherit font-lock-function-name-face :weight bold))) + "Face for an URL path in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-path-face 'openapi-yaml-path-face + "Face for paths and references in an OpenAPI YAML file.") + +(defface openapi-yaml-path-face + '((t (:inherit font-lock-string-face :weight bold))) + "Face for paths and references in an OpenAPI YAML file." + :group 'faces) + +(defvar openapi-yaml-definition-type-face 'openapi-yaml-definition-type-face + "Face for a definition type in an OpenAPI YAML file.") + +(defface openapi-yaml-definition-type-face + '((t (:inherit font-lock-type-face :weight bold))) + "Face for a definition type in an OpenAPI YAML file." + :group 'faces) + +(defun openapi-yaml-mode--key (value) + "Builds from a VALUE a regex string for a key that is not at the top level." + (format "^[[:space:]-]+\\(%s\\)[[:space:]]*:[[:space:]]" value)) + +(defconst openapi-yaml-mode--space-or-quote "[[:space:]\"']") + +(defun openapi-yaml-mode--string-constant (value) + "Builds from a VALUE a regex string for a string constant." + (format "\\(:\\|-\\)\\(%s*%s%s?\\)[[:space:]]*$" + openapi-yaml-mode--space-or-quote + value + openapi-yaml-mode--space-or-quote)) + +(defun openapi-yaml-mode--string-constant-for-key (value key) + "Builds from VALUE a regex string for a string constant associated to a KEY." + (format "^[[:space:]]*[:-]?[[:space:]]*%s[[:space:]]*\\(:\\|-\\)[[:space:]]*\n?[[:space:]]*\\(%s*%s%s?\\)[[:space:]]*$" + key openapi-yaml-mode--space-or-quote value openapi-yaml-mode--space-or-quote)) + +(defvar openapi-yaml-mode--font-lock-keywords + `( + ;; Url paths and reference paths share the same syntax highlight + ;; Url path key for Paths + ("^[[:space:]]*\\([\"\']?/[^[:space:]]*[\"\']?\\):[[:space:]]*$" 1 openapi-yaml-url-path-face) + ;; Url path value for host + ("^host[[:space:]]*:[[:space:]]\\(.*\\)$" 1 openapi-yaml-url-path-face) + ;; Url path value for basePath + ("^basePath[[:space:]]*:[[:space:]]\\(.*\\)$" 1 openapi-yaml-url-path-face) + ;; Path to a definition + (,(format "%s?#/[^\"\n\']*%s?[[:space:]]*$" openapi-yaml-mode--space-or-quote openapi-yaml-mode--space-or-quote) + . font-lock-string-face) + ;; Url values + ("[ \t]\\([\'\"]https?:[^[:space:]\"']*[\'\"]\\)[[:space:],]" 1 font-lock-string-face) + ("[ \t\"']\\(https?:[^[:space:]\"']*\\)[[:space:],\"']" 1 font-lock-string-face) + + ;; MIME types and formats share the same font face + ("[ \t'\"`]\\(application/[^:\"\\'`[:space:]]*\\)" 1 font-lock-type-face) + ("[ \t'\"`]\\(text/[^:\"\\'`[:space:]]*\\)" 1 font-lock-type-face) + ("[ \t'\"`]\\(multipart/[^:\"\\'`[:space:]]*\\)" 1 font-lock-type-face) + ("[ \t'\"`]\\(image/[^:\"\\'`[:space:]]*\\)" 1 font-lock-type-face) + ("[ \t'\"`]\\(charset=[\"\\']?[^:\"\\'`[:space:]]*[\"\\']?\\)" 1 font-lock-type-face) + ;; Types + (,(openapi-yaml-mode--string-constant-for-key "\\(integer\\|number\\|string\\|boolean\\|array\\|object\\)" "type") 2 font-lock-type-face) + ;; Formats + (,(openapi-yaml-mode--string-constant-for-key "\\(int32\\|int64\\|float\\double\\|byte\\|binary\\|date\\|date-time\\|password\\)" "format") 2 font-lock-type-face) + ;; Collection formats + (,(openapi-yaml-mode--string-constant-for-key "\\(csv\\|ssv\\|tsv\\|pipes\\|multi\\)" "collectionFormat") 2 font-lock-type-face) + + ;; Markdown syntax highlight + ;; Markdown header + ("^[ \t]+#+[[:space:]]*\\(.*\\)$" 1 openapi-yaml-markdown-header-face) + ;; Markdown link [] + ("\\([[][^]]*[]]\\)\\(([^[:space:]]*)\\)" 1 font-lock-keyword-face) + ;; Markdown link () + ("\\([[][^]]*[]]\\)\\(([^[:space:]]*)\\)" 2 font-lock-string-face) + ;; Markdown bold + ("[ \t_]\\*\\*\\([^\\*]*\\)\\*\\*[ \t_]" 1 openapi-yaml-markdown-bold-face append) + ("[ \t\\*]__\\([^\\_]*\\)__[ \t\\*]" 1 openapi-yaml-markdown-bold-face append) + ;; Markdown italic + ("[ \t_]\\*\\([^\\*[:space:]][^\\*]*\\)\\*[ \t_]" 1 openapi-yaml-markdown-italic-face append) + ("[ \t\\*]_\\([^_[:space:]][^_]*\\)_[ \t\\*]" 1 openapi-yaml-markdown-italic-face append) + ;; Markdown tables + ("\\(.*\\)[\r]?[\n][ \t]*|[ \t]?--.*|[ \t]*$" 1 openapi-yaml-markdown-table-bold-face t) + + ;; YAML comments (Markdown headers cannot be declared without some indentation) + ("^#[[:space:]]*.*$" . font-lock-comment-face) + ;; XML comments + ("" . font-lock-comment-face) + + ;; HTTP Status Codes as keys + ("^[[:space:]]*[\"']?[1-5][0-9][0-9][\"']?[[:space:]]*:[[:space:]]*$" . openapi-yaml-http-code-face) + + ;; HTTP methods as keys + (,(openapi-yaml-mode--key "\\(get\\|put\\|post\\|delete\\|options\\|head\\|patch\\)") 1 openapi-yaml-http-method-face) + + ;; Highlight for numbers + ("[ \t]\\(-?[[:digit:]]*\\.?[[:digit:]]*\\),?[[:space:]]+" 1 font-lock-constant-face) + + ;; Highlight null, true and false + ("[ \t]\\(null\\|true\\|false\\)[[:space:],]" 1 font-lock-constant-face) + + ;; Highlight operationId just like an url path + (,(openapi-yaml-mode--string-constant-for-key "\\([^[:space:]:][^[:space:]]*\\)" "operationId") 2 openapi-yaml-url-path-face) + + ;; Escape characters + ("\\([\\]\\)\\([tbnrf\'\"\\]\\)" + (1 font-lock-comment-face t) + (2 font-lock-keyword-face t)) + + ;; YAML key (YAML keys in Swagger files shouldn't include spaces) + ;; This allows to avoid many false positives when a sentence includes a : + ("^[ \t-]*\\([^/[:space:]:][^[:space:]:]*\\)[ \t-]*:[ \t-\r\n]" 1 font-lock-variable-name-face) + + ;; YAML key for OAuth scopes + ("^[ \t-]*\'\\([^/[:space:]][^[:space:]]*\\)[ \t-]*\':[ \t-\r\n]" 1 font-lock-variable-name-face) + + ;; HTTP headers + ("[ \t\\'\"`]\\(Accept\\|Accept-Charset\\|Accept-Encoding\\|Accept-Language\\|Accept-Datetime\\|Authorization\\|Cache-Control\\|Content-Type\\):[ \t]" 1 font-lock-constant-face) + + ;; HTTP methods in text before an url path + ("\\(GET\\|PUT\\|POST\\|DELETE\\|OPTIONS\\|HEAD\\|PATCH\\)[ \t]*\\(/[^[:space:]]*\\|http\\)" + (1 openapi-yaml-http-method-face) + (2 openapi-yaml-path-face)) + + ;; Query params in url paths + ("/\\({[^}/[:space:]]*}\\)" 1 font-lock-keyword-face t) + + ;; Path to a parameter + (,(format "%s?#/parameters/\\([^\"\n\']*\\)%s?[[:space:]]*$" openapi-yaml-mode--space-or-quote openapi-yaml-mode--space-or-quote) + 1 font-lock-keyword-face t))) + +(defvar openapi-yaml-mode--font-lock-keywords-for-openapi + (append openapi-yaml-mode--font-lock-keywords + `((,(format "%s?#/definitions/\\([^\"\n\']*\\)%s?[[:space:]]*$" openapi-yaml-mode--space-or-quote openapi-yaml-mode--space-or-quote) + 1 openapi-yaml-definition-type-face t)))) + +(defvar openapi-yaml-mode--font-lock-keywords-for-openapi3 + (append openapi-yaml-mode--font-lock-keywords + `((,(format "%s?#/components/schemas/\\([^\"\n\']*\\)%s?[[:space:]]*$" openapi-yaml-mode--space-or-quote openapi-yaml-mode--space-or-quote) + 1 openapi-yaml-definition-type-face t)))) + + ;;;###autoload +(define-derived-mode openapi-yaml-mode + yaml-mode "OpenAPI-YAML" + ;; Swagger specification is case sensitive + ;; (setq font-lock-keywords-case-fold-search t) + + (unless openapi-yaml-use-yaml-mode-syntax-highlight + (progn + (set-syntax-table openapi-yaml-mode--syntax-table) + + (set (make-local-variable 'font-lock-defaults) + (if (openapi-yaml-mode-detect-openapi2) + '(openapi-yaml-mode--font-lock-keywords-for-openapi nil nil) + '(openapi-yaml-mode--font-lock-keywords-for-openapi3 nil nil))))) + + (add-to-list 'completion-at-point-functions + (if (openapi-yaml-mode-detect-openapi2) + 'openapi-yaml-mode--openapi2-completion-at-point + 'openapi-yaml-mode--openapi3-completion-at-point))) + +(defun openapi-yaml-mode-detect-openapi2 () + "Detect if a file is an OpenAPI 2 file." + (and + (or (string-suffix-p ".yaml" (buffer-name)) + (string-suffix-p ".yml" (buffer-name))) + (string-match + "\\(.\\|\n\\)*\\([[:space:]]\\|\"\\|\\'\\)*swagger\\([[:space:]]\\|\"\\|\\'\\)*:[[:space:]]*[\"\\']2.0[\"\\'].*" + ;; Need to avoid stack overflow for multi-line regex + (buffer-substring 1 (min (buffer-size) + openapi-yaml-predicate-regexp-match-limit))))) + +(defun openapi-yaml-mode-detect-openapi3() + "Detect if a file is an OpenAPI 3 file." + (and + (or (string-suffix-p ".yaml" (buffer-name)) + (string-suffix-p ".yml" (buffer-name))) + (string-match + "\\(.\\|\n\\)*\\([[:space:]]\\|\"\\|\\'\\)*openapi\\([[:space:]]\\|\"\\|\\'\\)*:[[:space:]]*[\"\\']?3.0.0[\"\\']?.*" + ;; Need to avoid stack overflow for multi-line regex + (buffer-substring 1 (min (buffer-size) + openapi-yaml-predicate-regexp-match-limit))))) + +(defun openapi-yaml-mode-add-to-magic-mode-alist () + "Associate YAML files with an openapi or swagger element to openapi2-yaml-mode." + (add-to-list 'magic-mode-alist + '(openapi-yaml-mode-detect-openapi2 . openapi-yaml-mode)) + (add-to-list 'magic-mode-alist + '(openapi-yaml-mode-detect-openapi3 . openapi-yaml-mode))) + +(setq yaml-imenu-generic-expression + '(("*Elements*" "^ ? ?\\(:?[a-zA-Z_-]+\\):" 1) + ("*Paths*" "^[[:space:]]*[\\'\"]?\\(/[^:[:space:]]*\\)" 1) + ("*OperationIds*" "^[[:space:]]*[\\'\"]?operationId[\\'\"]?[[:space:]]*:[[:space:]]*[\\'\"]?\\([^\\'\"[:space:]]*\\)[\\'\"]?" 1))) + +(provide 'openapi-yaml-mode) +;;; openapi-yaml-mode.el ends here diff --git a/layers/ii-yaml/packages.el b/layers/ii-yaml/packages.el new file mode 100644 index 0000000..4382933 --- /dev/null +++ b/layers/ii-yaml/packages.el @@ -0,0 +1,73 @@ +;;; packages.el --- ii-yaml layer packages file for Spacemacs. +;; +;; Copyright (c) 2012-2018 Sylvain Benner & Contributors +;; +;; Author: +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +;;; Commentary: + +;; See the Spacemacs documentation and FAQs for instructions on how to implement +;; a new layer: +;; +;; SPC h SPC layers RET +;; +;; +;; Briefly, each package to be installed or configured by this layer should be +;; added to `ii-yaml-packages'. Then, for each package PACKAGE: +;; +;; - If PACKAGE is not referenced by any other Spacemacs layer, define a +;; function `ii-yaml/init-PACKAGE' to load and initialize the package. + +;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so +;; define the functions `ii-yaml/pre-init-PACKAGE' and/or +;; `ii-yaml/post-init-PACKAGE' to customize the package as it is loaded. + +;;; Code: + +(defconst ii-yaml-packages + `((openapi-yaml-mode + :location ,(concat (configuration-layer/get-layer-local-dir 'ii-yaml) "openapi-yaml-mode") + ) + (flycheck-swagger-tools + :location ,(concat (configuration-layer/get-layer-local-dir 'ii-yaml) "flycheck-swagger-tools") + ) + ) + "The list of Lisp packages required by the ii-yaml layer. + +Each entry is either: + +1. A symbol, which is interpreted as a package to be installed, or + +2. A list of the form (PACKAGE KEYS...), where PACKAGE is the + name of the package to be installed or loaded, and KEYS are + any number of keyword-value-pairs. + + The following keys are accepted: + + - :excluded (t or nil): Prevent the package from being loaded + if value is non-nil + + - :location: Specify a custom installation location. + The following values are legal: + + - The symbol `elpa' (default) means PACKAGE will be + installed using the Emacs package manager. + + - The symbol `local' directs Spacemacs to load the file at + `./local/PACKAGE/PACKAGE.el' + + - A list beginning with the symbol `recipe' is a melpa + recipe. See: https://github.com/milkypostman/melpa#recipe-format") + +(defun ii-yaml/init-openapi-yaml-mode () + (use-package openapi-yaml-mode) + ) +(defun ii-yaml/init-flycheck-swagger-tools () +(use-package flycheck-swagger-tools) +) +;;; packages.el ends here From 70319887b2f6ef9eb7dd99b5f7374af04ff8cda9 Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Mon, 18 May 2020 11:21:14 +1200 Subject: [PATCH 08/13] Adding delve to ii-go layer --- layers/ii-go/README.org | 3 +++ layers/ii-go/packages.el | 1 + 2 files changed, 4 insertions(+) diff --git a/layers/ii-go/README.org b/layers/ii-go/README.org index 786afd6..812acab 100644 --- a/layers/ii-go/README.org +++ b/layers/ii-go/README.org @@ -13,6 +13,7 @@ - [[#description][Description]] - [[#features][Features]] - [[#install][Install]] + - [[#delve][Delve]] * Description This layer extends the spacemacs go layer with additional configuration for use in literate programming. @@ -30,3 +31,5 @@ add =ii-go= to the existing =dotspacemacs-configuration-layers= list in this file. This layer assumes you have go installed. If not, you can install it following the guide [[https://golang.org/doc/install?download=go1.14.2.linux-amd64.tar.gz][on golang.org]] +** Delve +https://github.com/go-delve/delve/tree/master/Documentation/installation diff --git a/layers/ii-go/packages.el b/layers/ii-go/packages.el index 683e9cc..7e89f31 100644 --- a/layers/ii-go/packages.el +++ b/layers/ii-go/packages.el @@ -31,6 +31,7 @@ (defconst ii-go-packages '(lsp-ui + go-dlv (ob-go :location (recipe :fetcher github :repo "pope/ob-go"))) From d037a82fc3c0d24c20350e56ffc55340702ccd81 Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Tue, 19 May 2020 12:00:33 +1200 Subject: [PATCH 09/13] Add lsp and dap layers --- layers/ii-go/layers.el | 2 + layers/ii-go/packages.el | 87 +++++++++++++++------------------------- 2 files changed, 35 insertions(+), 54 deletions(-) diff --git a/layers/ii-go/layers.el b/layers/ii-go/layers.el index 9aaaf7a..fed88da 100644 --- a/layers/ii-go/layers.el +++ b/layers/ii-go/layers.el @@ -4,5 +4,7 @@ ;;;; (configuration-layer/declare-layer 'go) +(configuration-layer/declare-layer 'lsp) +(configuration-layer/declare-layer 'dap) ;;; layers.el ends here diff --git a/layers/ii-go/packages.el b/layers/ii-go/packages.el index 7e89f31..604d63a 100644 --- a/layers/ii-go/packages.el +++ b/layers/ii-go/packages.el @@ -2,74 +2,53 @@ ;; ;; Copyright (c) 2012-2018 Sylvain Benner & Contributors ;; -;; Author: -;; URL: https://github.com/syl20bnr/spacemacs +;; Author: Zach Mandeville +;; URL: https://github.com/humacs/.spacemacs.d ;; ;; This file is not part of GNU Emacs. ;; ;;; License: GPLv3 -;;; Commentary: - -;; See the Spacemacs documentation and FAQs for instructions on how to implement -;; a new layer: -;; -;; SPC h SPC layers RET -;; -;; -;; Briefly, each package to be installed or configured by this layer should be -;; added to `ii-go-packages'. Then, for each package PACKAGE: -;; -;; - If PACKAGE is not referenced by any other Spacemacs layer, define a -;; function `ii-go/init-PACKAGE' to load and initialize the package. - -;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so -;; define the functions `ii-go/pre-init-PACKAGE' and/or -;; `ii-go/post-init-PACKAGE' to customize the package as it is loaded. - -;;; Code: - (defconst ii-go-packages - '(lsp-ui - go-dlv + '(;; lsp-ui ; part of lsp layer + ;; go-dlv ; didn't quite fit the bill (ob-go :location (recipe :fetcher github :repo "pope/ob-go"))) - "The list of Lisp packages required by the ii-go layer. - -Each entry is either: - -1. A symbol, which is interpreted as a package to be installed, or - -2. A list of the form (PACKAGE KEYS...), where PACKAGE is the - name of the package to be installed or loaded, and KEYS are - any number of keyword-value-pairs. - - The following keys are accepted: - - - :excluded (t or nil): Prevent the package from being loaded - if value is non-nil - - - :location: Specify a custom installation location. - The following values are legal: - - - The symbol `elpa' (default) means PACKAGE will be - installed using the Emacs package manager. - - - The symbol `local' directs Spacemacs to load the file at - `./local/PACKAGE/PACKAGE.el' - - - A list beginning with the symbol `recipe' is a melpa - recipe. See: https://github.com/milkypostman/melpa#recipe-format") + "ob-go AND debugging via lsp+dap+dlv") (defun ii-go/init-ob-go () (use-package ob-go + ;; TODO check if gi/bin is in path :config (setenv "PATH" (concat user-home-directory "go/bin:" (getenv "PATH"))) + (setq exec-path (append exec-path (list (concat user-home-directory "go/bin"))) )) +;; (defun ii-go/init-lsp-go () +;; (use-package ob-go +;; :config +;; (setq +;; ) +;; ;; :config +;; ;; (setenv "PATH" (concat user-home-directory "go/bin:" (getenv "PATH"))) +;; ) + ) (defun ii-go/post-init-lsp-ui () (setq go-backend #'lsp)) - - - -;;; packages.el ends here +(defun ii-go/post-init-dap-go () + (dap-go-setup) + ) +(defun ii-go/post-init-lsp-layer () + (message "ii-go lsp-layer settings") + (setq-default + ;; we install to ~/go/bin + lsp-gopls-server-path "~/go/bin/gopls" + ) + ) + +;; (defun ii-go/init-go-dlv () +;; (use-package go-dlv +;; ;; NOTE: for kubemacs, dlv may be in /usr/local/bin +;; ;; :config +;; ;; (setenv "PATH" (concat user-home-directory "go/bin:" (getenv "PATH"))) +;; )) From bfbd66081648e07a2d1da59763cb42d9daf96b4e Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Tue, 19 May 2020 20:55:48 +1200 Subject: [PATCH 10/13] Add initial support for lsp / completion support for k8s manifests --- layers/ii-yaml/README.org | 7 +++++++ layers/ii-yaml/layers.el | 10 ++++++++++ layers/ii-yaml/packages.el | 2 ++ 3 files changed, 19 insertions(+) create mode 100644 layers/ii-yaml/README.org create mode 100644 layers/ii-yaml/layers.el diff --git a/layers/ii-yaml/README.org b/layers/ii-yaml/README.org new file mode 100644 index 0000000..2af92ff --- /dev/null +++ b/layers/ii-yaml/README.org @@ -0,0 +1,7 @@ + + + +#+name: foo +#+BEGIN_SRC sh + npm i -g yaml-language-server +#+END_SRC diff --git a/layers/ii-yaml/layers.el b/layers/ii-yaml/layers.el new file mode 100644 index 0000000..bf07068 --- /dev/null +++ b/layers/ii-yaml/layers.el @@ -0,0 +1,10 @@ +;;;; +;; L A Y E R S +;; Depend on the go layer and GO from there. +;;;; + +(configuration-layer/declare-layer '(yaml + :variables + yaml-enable-lsp t)) + +;;; layers.el ends here diff --git a/layers/ii-yaml/packages.el b/layers/ii-yaml/packages.el index 4382933..99d7854 100644 --- a/layers/ii-yaml/packages.el +++ b/layers/ii-yaml/packages.el @@ -70,4 +70,6 @@ Each entry is either: (defun ii-yaml/init-flycheck-swagger-tools () (use-package flycheck-swagger-tools) ) +;; TODO needs better logic to only apply this to kubernetes manifests +(puthash :kubernetes "/*yaml" (symbol-value 'lsp-yaml-schemas)) ;;; packages.el ends here From be34f2cd482abca3459ef80612290e4c0c7f96e6 Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Thu, 21 May 2020 10:09:01 +1200 Subject: [PATCH 11/13] Add lsp-yaml-schemas to default to k8s resources by default --- layers/ii-yaml/packages.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/layers/ii-yaml/packages.el b/layers/ii-yaml/packages.el index 99d7854..6bb1b6f 100644 --- a/layers/ii-yaml/packages.el +++ b/layers/ii-yaml/packages.el @@ -71,5 +71,8 @@ Each entry is either: (use-package flycheck-swagger-tools) ) ;; TODO needs better logic to only apply this to kubernetes manifests -(puthash :kubernetes "/*yaml" (symbol-value 'lsp-yaml-schemas)) +(defun ii-yaml/post-init-lsp-mode () + (let ((ii-yaml-schemas (make-hash-table))) + (puthash :kubernetes "/*yaml" lsp-yaml-schemas) + (setq lsp-yaml-schemas ii-yaml-schemas))) ;;; packages.el ends here From 02ff000663750beee988b0ffd7eda829829fd4b1 Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Sat, 23 May 2020 21:11:24 +1200 Subject: [PATCH 12/13] Delete custom file --- custom.el | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 custom.el diff --git a/custom.el b/custom.el deleted file mode 100644 index e69de29..0000000 From 9c94bf230d3a4af503d6419363e39f126e06e4de Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Sat, 23 May 2020 21:12:20 +1200 Subject: [PATCH 13/13] Update .gitignore w/ custom.el --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1e417a4..7ea8f90 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -./custom.el +custom.el