# -*- orgstrap-cypher: sha256; orgstrap-norm-func-name: orgstrap-norm-func--dprp-1-0; orgstrap-block-checksum: 087bc07694763650335941593bf488ea9037fb2de64d4f87bc3892486c646d9f; -*-
# [[orgstrap][jump to the orgstrap block for this file]]
#+title: Welcome

* Welcome to SCKAN!

SCKAN is the *SPARC Connectivity Knowledge base of the Autonomic Nervous system*.

This docker image contains everything you need to query SCKAN.

Get started with the [[./tutorial.org][Tutorial]].

Write your own queries in [[./scratch.org][Scratch]].

Review [[./examples.org][Examples]].

Browse the full [[./queries.org][Catalog]].

** Saving your work
You can quit at any time and your work will be saved.

You can continue your previous session by running
=docker start -ai $(docker ps -lqf ancestor=tgbugs/musl:kg-release-user)=

For more details see [[./tutorial.org::#saving-and-restoring][Saving and restoring]] in the reference section.

** Saving to the host system
While using =docker start= keeps you safe from losing work,
the best way to save your work across sessions is to mount
a folder from the host system to the docker container.

To configure your system so that your work lives on the host
system see [[./tutorial.org::#saving-to-the-host-system][Saving to the host system]] in the reference section.

** Additional documentation
- [[./overview.org][Overview, background, and glossary]]

** Web links
- [[https://scicrunch.org/sawg/about/SCKAN][About SCKAN]]
- [[https://commonfund.nih.gov/sparc][About SPARC]]
- [[https://doi.org/10.5281/zenodo.5337441][Latest SCKAN data release]]
- [[https://github.com/SciCrunch/sparc-curation/blob/master/docs/sckan/welcome.org][GitHub source for this file]]

* Bootstrap :noexport:

To get the correct behavior for restoring desktops when using this file as an entrypoint use the following command.
#+begin_src bash
emacs -eval "(find-file-noselect (pop argv))" welcome.org
#+end_src

#+name: orgstrap
#+begin_src elisp :results none :exports none :lexical yes
(defvar ow-do-devel nil)

(defun switch-to-or-find-file-other-tab (name &optional noselect)
  (let* ((buffer (find-file-noselect name))
         (buffer-name (buffer-name buffer)))
    (if (tab-bar--tab-index-by-name buffer-name)
        (tab-bar-switch-to-tab buffer-name)
      ;; FIXME `find-file-other-tab' breaks narrowing this is the workaround
      (tab-bar-new-tab 1)
      (switch-to-buffer buffer)
      (when noselect (tab-bar-switch-to-prev-tab)))))

(defun advise--sbkt (fun &rest args)
  "Invert C-u C-x C-c behavior so that quit saves all visited files silently."
  (apply fun (mapcar #'not args)))

;; make backup to a designated dir, mirroring the full path
(defun --backup-file-name (fpath)
  "Return a new file path of a given file path.
   If the new path's directories does not exist, create them."
  (let* ((backup-root-dir "~/.emacs.d/emacs-backup/")
         (file-path (replace-regexp-in-string "[A-Za-z]:" "" fpath)) ; remove Windows driver letter in path, for example, “C:”
         (backup-file-path (replace-regexp-in-string "//" "/" (concat backup-root-dir file-path "~"))))
    (make-directory (file-name-directory backup-file-path) (file-name-directory backup-file-path))
    backup-file-path))

(unless ow-do-devel

  ;;; prevent creation of files that will confuse the user
  (setq make-backup-file-name-function '--backup-file-name)

  ;; Save all tempfiles in $TMPDIR/emacs$UID/
  (defconst emacs-tmp-dir (file-name-as-directory (expand-file-name (format "emacs%d" (user-uid)) temporary-file-directory)))
  (setq backup-directory-alist
        `((".*" . ,emacs-tmp-dir)))
  (setq auto-save-file-name-transforms
        `((".*" ,emacs-tmp-dir t)))
  (setq auto-save-list-file-prefix
        emacs-tmp-dir)

  (find-file-noselect "./queries.org")
  (global-set-key (kbd "C-q") #'save-buffers-kill-terminal)
  (global-unset-key (kbd "C-w")) ; cut is too dangerous, a user wouldn't know what they have done
  (advice-add #'save-buffers-kill-terminal :around #'advise--sbkt)
  (setq org-link-frame-setup
        '((vm . vm-visit-folder-other-frame)
          (vm-imap . vm-visit-imap-folder-other-frame)
          (gnus . org-gnus-no-new-news)
          (file . switch-to-or-find-file-other-tab)
          (wl . wl-other-frame)))
  (font-lock-add-keywords
   nil
   '(("^\\*+ " ; hide the stars in headlines
      (0
       (prog1 nil
         (put-text-property
          (match-beginning 0)
          (match-end 0)
          'invisible t))))))
  (goto-char 0)
  (org-next-visible-heading 1)
  (org-narrow-to-subtree)
  (read-only-mode)

  (setq org-file-apps
        (append org-file-apps
                '(("\\.jpeg\\'" . "feh \"%s\"")
                  ("\\.png\\'" . "feh \"%s\""))))

  (setq desktop-path (list user-emacs-directory))
  (setq desktop-dirname user-emacs-directory)
  (setq desktop-save t)
  (desktop-save-mode 1)
  (let ((buffer (current-buffer)))
    (desktop-read)
    (let ((have-vterm-tab
           (cl-loop for tab in (tab-bar-tabs) when (string= (cdr (assq 'name tab)) "*vterm*") return t)))
      (if have-vterm-tab (tab-bar-switch-to-tab "*vterm*") (tab-bar-new-tab 1))
      (let ((vb (vterm))) ; `desktop-save-mode' does not restore the process, only the tab
        (switch-to-buffer vb)
        (tab-bar-switch-to-recent-tab)))
    (set-process-query-on-exit-flag (get-process "vterm") nil)
    (unless (and (desktop-owner) (= (desktop-owner) (emacs-pid)))
      ;; XXX this is a bit evil if you were to try to naievely `find-file-noselect' this file
      (pop-to-buffer-same-window buffer))))
#+end_src

To test save and restore for this file use the following command.
#+begin_src bash
emacs -Q -eval "(progn (setq user-init-file (concat default-directory (pop argv)) _ (load user-init-file) user-emacs-directory (file-name-directory user-init-file)) (find-file-noselect (pop argv)))" test-sandbox/.emacs.d/init.el welcome.org
#+end_src

** Local Variables :ARCHIVE:
# Local Variables:
# org-adapt-indentation: nil
# org-edit-src-content-indentation: 0
# org-hide-emphasis-markers: t
# eval: (progn (setq-local orgstrap-min-org-version "8.2.10") (let ((a (org-version)) (n orgstrap-min-org-version)) (or (fboundp #'orgstrap--confirm-eval) (not n) (string< n a) (string= n a) (error "Your Org is too old! %s < %s" a n))) (defun orgstrap-norm-func--dprp-1-0 (body) (let ((p (read (concat "(progn\n" body "\n)"))) (m '(defun defun-local defmacro defvar defvar-local defconst defcustom)) print-quoted print-length print-level) (cl-labels ((f (b) (cl-loop for e in b when (listp e) do (or (and (memq (car e) m) (let ((n (nthcdr 4 e))) (and (stringp (nth 3 e)) (or (cl-subseq m 3) n) (f n) (or (setcdr (cddr e) n) t)))) (f e))) p)) (prin1-to-string (f p))))) (unless (boundp 'orgstrap-norm-func) (defvar-local orgstrap-norm-func orgstrap-norm-func-name)) (defun orgstrap-norm-embd (body) (funcall orgstrap-norm-func body)) (unless (fboundp #'orgstrap-norm) (defalias 'orgstrap-norm #'orgstrap-norm-embd)) (defun orgstrap--confirm-eval-minimal (lang body) (not (and (member lang '("elisp" "emacs-lisp")) (eq orgstrap-block-checksum (intern (secure-hash orgstrap-cypher (orgstrap-norm body))))))) (unless (fboundp #'orgstrap--confirm-eval) (defalias 'orgstrap--confirm-eval #'orgstrap--confirm-eval-minimal)) (let (enable-local-eval) (vc-find-file-hook)) (let ((ocbe org-confirm-babel-evaluate) (obs (org-babel-find-named-block "orgstrap"))) (if obs (unwind-protect (save-excursion (setq-local orgstrap-norm-func orgstrap-norm-func-name) (setq-local org-confirm-babel-evaluate #'orgstrap--confirm-eval) (goto-char obs) (org-babel-execute-src-block)) (when (eq org-confirm-babel-evaluate #'orgstrap--confirm-eval) (setq-local org-confirm-babel-evaluate ocbe)) (org-set-visibility-according-to-property)) (warn "No orgstrap block."))))
# End:
