Skip to content

jacobzlogar/emax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emacs literate configuration

About

When cloning this repo, make sure to clone the submodules

./images/theme.png

early-init.el

I just prefer this for now, load times are fast

(setq user-emacs-directory "~/.config/emax")
(add-to-list 'load-path (expand-file-name "packages/evil" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "packages/compat" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "packages/vertico" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "packages/corfu" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "packages/ef-themes" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "packages/fontaine" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "packages/eldoc-box" user-emacs-directory))
(require 'evil)
(require 'compat)
(require 'vertico)
(require 'corfu)
(require 'ef-themes)
(require 'fontaine)
(require 'eldoc-box)
(require 'project)
(evil-mode)
(vertico-mode)
(corfu-mode)
(global-corfu-mode)
(load (expand-file-name "init.el" user-emacs-directory))
(mapc 'load (file-expand-wildcards (format "%s/modules/*.el" user-emacs-directory)))

init.el

Bootstrap package.el and use-package

(require 'package)
(setq custom-safe-themes t)
(add-to-list
 'package-archives
 '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(eval-when-compile
  (require 'use-package))
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(setq use-package-always-ensure t)

Setup some modes & some configurations

(electric-pair-mode)
(smartparens-mode)
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))
(add-hook 'typescript-ts-mode-hook 'eglot-ensure)
(add-hook 'rust-ts-mode 'eglot-ensure)
(add-hook 'vue-mode 'eglot-ensure)
(add-to-list 'major-mode-remap-alist
	     '(rustic-mode . rust-ts-mode)
	     '(typescript-mode . typescript-ts-mode))
(setq warning-minimum-level :emergency)

Configure backup & auto save directories

(setq delete-auto-save-files t)
(setq create-lockfiles nil)
(setq backup-directory-alist
      '(("." . "~/.emacs.d/backups")))
(setq auto-save-file-name-transforms
      `((".*" ,(expand-file-name "~/tmp/emacs-autosaves/") t)))

packages

git-gutter

https://ianyepan.github.io/posts/emacs-git-gutter/

(use-package git-gutter
  :hook (prog-mode . git-gutter-mode)
  :config
  (setq git-gutter:update-interval 0.02))

(use-package git-gutter-fringe
  :config
  (set-face-attribute 'git-gutter-fr:added nil :background nil)
  (set-face-attribute 'git-gutter-fr:modified nil :background nil)
  (set-face-attribute 'git-gutter-fr:deleted nil :background nil)
  (define-fringe-bitmap 'git-gutter-fr:added [24 24 24 255 24 24 24] nil nil 'center)
  (define-fringe-bitmap 'git-gutter-fr:modified [24 24 24 24 24 24 24 24 0 24 24 24] nil nil 'center)
  (define-fringe-bitmap 'git-gutter-fr:deleted [129 66 36 24 36 66 129] nil nil 'center))

evil-collection

(use-package evil-collection
  :after evil
  :ensure t
  :config
  (evil-collection-init))

spacious-padding

(use-package spacious-padding
  :init
  (spacious-padding-mode))

dape-mode

(use-package dape)

modeline

(setq flymake-modeline-counter-format '(flymake-mode-line-error-counter flymake-mode-line-warning-counter
 flymake-mode-line-note-counter))

(setq mode-line-format nil)
(kill-local-variable 'mode-line-format)
(force-mode-line-update)

(defface modeline/bold-shadow
  `((t :inherit bold :foreground ,(face-foreground 'shadow)))
  "Face for bold+shadow")

(defvar modeline/symbol
  (propertize "λ" 'face '(:background ,(face-background 'mode-line) :inherit 'bold)))

(put 'modeline/symbol 'risky-local-variable-p t)

(defun modeline/file ()
  (if (and (consp (project-current)) (buffer-file-name))
      (file-relative-name buffer-file-name (project-root (project-current))) (buffer-name)))

(defun modeline/project ()
  (if (project-current)
      (propertize (project-name (project-current)) 'face 'bold) ""))

(defun modeline/vcs ()
  (if (and (project-current) (mode-line-window-selected-p))
      (format "%s %s" (propertize "" 'face 'shadow) (vc-git--symbolic-ref (buffer-file-name))) ""))

(defun modeline/mode ()
  (format "%s %s" (propertize
		   (symbol-name major-mode)
		   'face 'modeline/bold-shadow)
		   (nerd-icons-icon-for-file buffer-file-name)))

(defun modeline/padding (item &optional dir)
  (cond ((eq dir 'left) (format " %s" item))
        ((eq dir 'right) (format "%s " item))
        (t (format "%s" item))))

(defun modeline/eglot ()
  (if (eglot-managed-p)
      (propertize "" 'face '(:foreground "green")) ""))

(setq-default mode-line-format
	      '((:eval (modeline/padding (modeline/project) 'left))
		vc-mode
		(:eval (propertize "%+" 'face 'modeline/bold-shadow))
		" Line: %l"
		(:eval (modeline/padding (modeline/eglot) 'left))
		(flymake-mode-line-exception flymake-mode-line-counters)
		(:eval (propertize
			" " 'display
			`((space :align-to (- (+ right right-fringe right-margin)
					      ,(+ 2 (string-width (modeline/mode))))))))
		(:eval (modeline/padding (modeline/mode) 'right))))

(setq-default header-line-format
	      '((:eval (if (mode-line-window-selected-p) (modeline/padding modeline/symbol 'left)))
		(:eval (if (mode-line-window-selected-p) (modeline/padding (modeline/file) 'left)))))

evil

(use-package evil
  :custom
  (evil-undo-system 'undo-redo))

corfu

(use-package corfu
  :custom
  (corfu-cycle t)
  (corfu-preselect 'prompt)
  :bind
  (:map corfu-map
	("TAB" . corfu-next)
	([tab] . corfu-next)
	("S-TAB" . corfu-previous)
	([backtab] . corfu-previous)))

corfu candidate overlay

(use-package corfu-candidate-overlay
  :after corfu
  :config
  ;; enable corfu-candidate-overlay mode globally
  ;; this relies on having corfu-auto set to nil
  (corfu-candidate-overlay-mode +1))

cape completions for corfu

(use-package cape
  :init
  (add-hook 'completion-at-point-functions #'cape-file))

dabbrev config

;; Use Dabbrev with Corfu!
(use-package dabbrev
  ;; Swap M-/ and C-M-/
  :bind (("M-/" . dabbrev-completion)
	   ("C-M-/" . dabbrev-expand))
  :config
  (add-to-list 'dabbrev-ignored-buffer-regexps "\\` ")
  ;; Since 29.1, use `dabbrev-ignored-buffer-regexps' on older.
  (add-to-list 'dabbrev-ignored-buffer-modes 'doc-view-mode)
  (add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode)
  (add-to-list 'dabbrev-ignored-buffer-modes 'tags-table-mode))

winuum config

;; (use-package winum
;;   :init
;;   (winum-mode))

consult config

;; Example configuration for Consult
(use-package consult
  ;; Replace bindings. Lazily loaded by `use-package'.
  :bind (;; C-c bindings in `mode-specific-map'
	   ("C-c M-x" . consult-mode-command)
	   ("C-c h" . consult-history)
	   ("C-c k" . consult-kmacro)
	   ("C-c m" . consult-man)
	   ("C-c i" . consult-info)
	   ([remap Info-search] . consult-info)
	   ;; C-x bindings in `ctl-x-map'
	   ("C-x M-:" . consult-complex-command)     ;; orig. repeat-complex-command
	   ("C-x b" . consult-buffer)                ;; orig. switch-to-buffer
	   ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
	   ("C-x 5 b" . consult-buffer-other-frame)  ;; orig. switch-to-buffer-other-frame
	   ("C-x t b" . consult-buffer-other-tab)    ;; orig. switch-to-buffer-other-tab
	   ("C-x r b" . consult-bookmark)            ;; orig. bookmark-jump
	   ("C-x p b" . consult-project-buffer)      ;; orig. project-switch-to-buffer
	   ;; Custom M-# bindings for fast register access
	   ("M-#" . consult-register-load)
	   ("M-'" . consult-register-store)          ;; orig. abbrev-prefix-mark (unrelated)
	   ("C-M-#" . consult-register)
	   ;; Other custom bindings
	   ("M-y" . consult-yank-pop)                ;; orig. yank-pop
	   ;; M-g bindings in `goto-map'
	   ("M-g e" . consult-compile-error)
	   ("M-g f" . consult-flymake)               ;; Alternative: consult-flycheck
	   ("M-g g" . consult-goto-line)             ;; orig. goto-line
	   ("M-g M-g" . consult-goto-line)           ;; orig. goto-line
	   ("M-g o" . consult-outline)               ;; Alternative: consult-org-heading
	   ("M-g m" . consult-mark)
	   ("M-g k" . consult-global-mark)
	   ("M-g i" . consult-imenu)
	   ("M-g I" . consult-imenu-multi)
	   ;; M-s bindings in `search-map'
	   ("M-s d" . consult-find)                  ;; Alternative: consult-fd
	   ("M-s c" . consult-locate)
	   ("M-s g" . consult-grep)
	   ("M-s G" . consult-git-grep)
	   ("M-s r" . consult-ripgrep)
	   ("M-s l" . consult-line)
	   ("M-s L" . consult-line-multi)
	   ("M-s k" . consult-keep-lines)
	   ("M-s u" . consult-focus-lines)
	   ;; Isearch integration
	   ("M-s e" . consult-isearch-history)
	   ("M-p a" . project-find-file)
	   ("M-p f" . consult-recent-file)
	   :map isearch-mode-map
	   ("M-e" . consult-isearch-history)         ;; orig. isearch-edit-string
	   ("M-s e" . consult-isearch-history)       ;; orig. isearch-edit-string
	   ("M-s l" . consult-line)                  ;; needed by consult-line to detect isearch
	   ("M-s L" . consult-line-multi)            ;; needed by consult-line to detect isearch
	   ;; Minibuffer history
	   :map minibuffer-local-map
	   ("M-s" . consult-history)                 ;; orig. next-matching-history-element
	   ("M-r" . consult-history))                ;; orig. previous-matching-history-element

  ;; Enable automatic preview at point in the *Completions* buffer. This is
  ;; relevant when you use the default completion UI.
  :hook (completion-list-mode . consult-preview-at-point-mode)

  ;; The :init configuration is always executed (Not lazy)
  :init

  ;; Tweak the register preview for `consult-register-load',
  ;; `consult-register-store' and the built-in commands.  This improves the
  ;; register formatting, adds thin separator lines, register sorting and hides
  ;; the window mode line.
  (advice-add #'register-preview :override #'consult-register-window)
  (setq register-preview-delay 0.5)

  ;; Use Consult to select xref locations with preview
  (setq xref-show-xrefs-function #'consult-xref
	  xref-show-definitions-function #'consult-xref)

  ;; Configure other variables and modes in the :config section,
  ;; after lazily loading the package.
  :config

  ;; Optionally configure preview. The default value
  ;; is 'any, such that any key triggers the preview.
  ;; (setq consult-preview-key 'any)
  ;; (setq consult-preview-key "M-.")
  ;; (setq consult-preview-key '("S-<down>" "S-<up>"))
  ;; For some commands and buffer sources it is useful to configure the
  ;; :preview-key on a per-command basis using the `consult-customize' macro.
  (consult-customize
   consult-theme :preview-key '(:debounce 0.2 any)
   consult-ripgrep consult-git-grep consult-grep consult-man
   consult-bookmark consult-recent-file consult-xref
   consult--source-bookmark consult--source-file-register
   consult--source-recent-file consult--source-project-recent-file
   ;; :preview-key "M-."
   :preview-key '(:debounce 0.4 any))

  ;; Optionally configure the narrowing key.
  ;; Both < and C-+ work reasonably well.
  (setq consult-narrow-key "<") ;; "C-+"

  ;; Optionally make narrowing help available in the minibuffer.
  ;; You may want to use `embark-prefix-help-command' or which-key instead.
  ;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
)

embark config

(use-package embark
  :ensure t

  :bind
  (("C-." . embark-act)         ;; pick some comfortable binding
   ("C-;" . embark-dwim)        ;; good alternative: M-.
   ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'

  :init

  ;; Optionally replace the key help with a completing-read interface
  (setq prefix-help-command #'embark-prefix-help-command)

  ;; Show the Embark target at point via Eldoc. You may adjust the
  ;; Eldoc strategy, if you want to see the documentation from
  ;; multiple providers. Beware that using this can be a little
  ;; jarring since the message shown in the minibuffer can be more
  ;; than one line, causing the modeline to move up and down:

  ;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
  ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)

  :config

  ;; Hide the mode line of the Embark live/completions buffers
  (add-to-list 'display-buffer-alist
               '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
                 nil
                 (window-parameters (mode-line-format . none)))))

;; Consult users will also want the embark-consult package.
(use-package embark-consult
  :ensure t ; only need to install it, embark loads it after consult if found
  :hook
  (embark-collect-mode . consult-preview-at-point-mode))

marginalia config

;;(use-package marginalia
  ;;:ensure t
  ;;:init
  ;;(marginalia-mode))

orderless config

;; Optionally use the `orderless' completion style.
(use-package orderless
  :custom
  ;; Configure a custom style dispatcher (see the Consult wiki)
  ;; (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch))
  ;; (orderless-component-separator #'orderless-escapable-split-on-space)
  (completion-styles '(orderless basic))
  (completion-category-defaults nil)
  (completion-category-overrides '((file (styles partial-completion)))))

vertico config

;; A few more useful configurations...
(use-package emacs
  :custom
  ;; Emacs 30 and newer: Disable Ispell completion function.
  ;; Try `cape-dict' as an alternative.
  (text-mode-ispell-word-completion nil)
  ;; Support opening new minibuffers from inside existing minibuffers.
  (enable-recursive-minibuffers t)
  ;; Hide commands in M-x which do not work in the current mode.  Vertico
  ;; commands are hidden in normal buffers. This setting is useful beyond
  ;; Vertico.
  (read-extended-command-predicate #'command-completion-default-include-p)
  ;; Enable indentation+completion using the TAB key.
  ;; `completion-at-point' is often bound to M-TAB.
  (tab-always-indent 'complete)
  :init
  ;; Add prompt indicator to `completing-read-multiple'.
  ;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
  (defun crm-indicator (args)
    (cons (format "[CRM%s] %s"
		  (replace-regexp-in-string
		   "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
		   crm-separator)
		  (car args))
	  (cdr args)))
  (advice-add #'completing-read-multiple :filter-args #'crm-indicator)

  ;; Do not allow the cursor in the minibuffer prompt
  (setq minibuffer-prompt-properties
	'(read-only t cursor-intangible t face minibuffer-prompt))
  (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode))

;; Enable vertico-multiform
(vertico-multiform-mode)
(setq vertico-cycle t)

;; Configure the display per command.
;; Use a buffer with indices for imenu
;; and a flat (Ido-like) menu for M-x.
(setq vertico-multiform-commands
      '((consult-imenu buffer indexed)
	(find-file flat)
	(project-find-file flat)
	(consult-fd flat)
	(execute-extended-command flat)))

;; Configure the display per completion category.
;; Use the grid display for files and a buffer
;; for the consult-grep commands.
(setq vertico-multiform-categories
      '((file grid)
	(consult-grep buffer)))

ui

tab bar

theme

ty mr. Prot

  • Why does switching from doom-gruvbox to one of these themes with ef-themes-select not change the gutter faces
(provide 'ui)
;;(load-theme 'doom-gruvbox)
  ;; Make customisations that affect Emacs faces BEFORE loading a theme
  ;; (any change needs a theme re-load to take effect).

  ;; If you like two specific themes and want to switch between them, you
  ;; can specify them in `ef-themes-to-toggle' and then invoke the command
  ;; `ef-themes-toggle'.  All the themes are included in the variable
  ;; `ef-themes-collection'.
  ;; (setq ef-themes-to-toggle '(ef-frost ef-symbiosis))

  ;; (setq ef-themes-headings ; read the manual's entry or the doc string
  ;; 	'((0 variable-pitch light 1.9)
  ;; 	  (1 variable-pitch light 1.8)
  ;; 	  (2 variable-pitch regular 1.7)
  ;; 	  (3 variable-pitch regular 1.6)
  ;; 	  (4 variable-pitch regular 1.5)
  ;; 	  (5 variable-pitch 1.4) ; absence of weight means `bold'
  ;; 	  (6 variable-pitch 1.3)
  ;; 	  (7 variable-pitch 1.2)
  ;; 	  (t variable-pitch 1.1)))

  ;; They are nil by default
  ;; (setq ef-themes-mixed-fonts t
  ;; 	ef-themes-variable-pitch-ui t)

  ;; Disable all other themes to avoid awkward blending:
  ;; (mapc #'disable-theme custom-enabled-themes)

  ;; Load the theme of choice:
  ;;(load-theme 'ef-night :no-confirm)

  ;; OR use this to load the theme which also calls `ef-themes-post-load-hook':
  (ef-themes-select 'ef-duo-dark)

  ;; The themes we provide are recorded in the `ef-themes-dark-themes',
  ;; `ef-themes-light-themes'.

  ;; We also provide these commands, but do not assign them to any key:
  ;;
  ;; - `ef-themes-toggle'
  ;; - `ef-themes-select'
  ;; - `ef-themes-select-dark'
  ;; - `ef-themes-select-light'
  ;; - `ef-themes-load-random'
  ;; - `ef-themes-preview-colors'
  ;; - `ef-themes-preview-colors-current'

Fonts

Hi, Is this garamond?

(set-frame-font "Iosevka 14")
;; (set-frame-font "Aporetic Sans Mono 14")
;; (fontaine-set-preset (or (fontaine-restore-latest-preset) 'regular))
;; (fontaine-mode 1)
;; (add-hook 'org-mode-hook 'variable-pitch-mode)
;; (add-hook 'org-mode-hook 'visual-line-mode)
;; (setq fontaine-presets
;;       '((regular
;; 	 :default-family "Aporetic Sans Mono"
;; 	 ;; :variable-pitch-family "EB Garamond Regular"
;; 	 :fixed-pitch-family "Aporetic Sans Mono"
;; 	 :default-height 150)))

modes

Some default emacs “ui” modes i’d like to disable

;; use git-gutter-mode
(setq auto-fill-width 80)
(setq git-gutter-mode t)
(setq git-gutter-fringe t)
(which-key-mode 1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(toggle-scroll-bar -1)
(winner-mode 1)
(setq blink-cursor-mode nil)
(add-hook 'prog-mode-hook (lambda () (set-fringe-style 20)))
;; (add-hook 'prog-mode-hook (setq fringe-mode 20))
(add-hook 'prog-mode-hook 'display-fill-column-indicator-mode)
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(add-hook 'prog-mode-hook 'toggle-truncate-lines)

org-mode

org-mode face customizations

(set-face-attribute 'header-line nil
 :background (face-background 'default)
 :underline `(:color ,(face-background 'mode-line) :position t)
 :box `(:color ,(face-background 'default) :line-width 4))

(let ((bg-color (face-attribute 'menu :background))
      (fg-color (face-attribute 'default :foreground)))
  (custom-set-faces
   `(org-block-begin-line ((t (:foreground ,fg-color :background ,bg-color))))
   `(org-block-end-line ((t (:foreground ,fg-color :background ,bg-color))))))

misc

(setq max-mini-window-height 1)
(set-fringe-style 20)
(let ((bg-color (face-attribute 'default :background)))
  (custom-set-faces
   `(flymake-error ((t :underline nil)))
   `(eglot-highlight-symbol-face ((t :inherit 'underline :weight normal)))
   `(eldoc-box-border ((t :background ,(face-attribute 'highlight :background))))
   `(line-number ((t (:background ,bg-color))))
   `(fringe ((t (:background ,bg-color))))))

kind icon

Am i even using this?

(use-package origami
  :init
  (global-origami-mode))
(use-package kind-icon
  :ensure t
  :after corfu
  ;:custom
  ; (kind-icon-blend-background t)
  ; (kind-icon-default-face 'corfu-default) ; only needed with blend-background
  :config
  (setq kind-icon-use-icons nil)
  (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))

keybindings

buffer

(global-set-key (kbd "C-<tab>") #'evil-switch-to-windows-last-buffer)
(evil-global-set-key 'motion (kbd "K") 'eldoc-doc-buffer)
(evil-global-set-key 'motion (kbd "\"") 'eldoc-box-quit-frame)
(global-set-key (kbd "C-a") #'project-find-file)
;; (global-set-key (kbd "C-o") #'eshell)

misc

config

I should move these into more specific sections

(setq org-src-window-setup 'current-window)
(setq org-src-tab-acts-natively t)
(setq org-src-preserve-indentation t)
(setq org-edit-src-content-indentation 0)
(add-hook 'org-mode-hook 'electric-indent-mode)
(setq project-switch-commands 'project-find-file)
(setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 1024 1024)) ;; 1mb

miscellanea

(defun nasm/compile (instr &optional bits)
  (let* ((bits (or bits 16))
	 (temp-asm "/tmp/test.asm")
	 (temp-binary "/tmp/test")
	 (cmd (format "nasm %s -o %s" temp-asm temp-binary)))
    (with-temp-file temp-asm
      (insert (format "bits %d\n" bits))
      (insert instr))
    (shell-command-to-string cmd)
    (when (file-exists-p temp-binary)
      (with-temp-buffer
	(insert-file-contents-literally temp-binary)
        (mapconcat (lambda (byte) (format "%02X" byte))
                   (string-to-list (buffer-substring-no-properties (point-min) (point-max)))
                   " ")))))

(defun ce/gen_const/seg_instr ()
  (interactive)
  (let* ((segmentRegister (completing-read "segment register: " '(("ES") ("CS") ("SS") ("DS"))))
	 (selectedMnemonic (completing-read "mnemonic: " '(("POP") ("PUSH"))))
	 (wide (completing-read "wide: " '(("true") ("false"))))
	 (const_name (format "pub const %s_%s: Instruction2 = Instruction2 {" selectedMnemonic segmentRegister))
	 (mnemonic (format "mnemonic: Mnemonic::%s," selectedMnemonic))
	 (operand (format "operand: Some(Operand::SegmentRegister { dest: SegmentRegister::%s })," segmentRegister))
	 (wide (format "wide: %s," wide))
	 (direction (format "direction: None"))
	 (body (mapconcat (lambda (s) (concat "    " s)) (list mnemonic operand wide direction) "\n"))
	 (message body)
	 (with-temp-buffer
	   (insert (format "%s\n%s\n};" const_name body))))))

(setq org-html-postamble-format '(("en" "<p class=\"author\">%a (%e) </p>")))
(define-derived-mode vue-mode web-mode "Vue Mode"
  "Major mode for .vue files"
  (setq web-mode-code-indent-offset 2)
  (setq web-mode-enable-auto-pairing nil)
  (setq web-mode-script-padding 0))

(add-to-list 'auto-mode-alist '("\\.vue\\'" . vue-mode))
(require 'json)

(defvar spacetraders/account-token
  (getenv "SPACETRADERS_ACCOUNT_TOKEN")
  "The token used to manage your account? Agent? idgi")

(setq spacetraders/api-key (getenv "SPACETRADERS_API_KEY"))

(setq spacetraders/buffer (get-buffer-create "*The Spice Must Flow*"))

(defun spacetraders/process ()
  (make-network-process
   :name "*The Spice Must Flow*"
   :buffer spacetraders/buffer
   :host "api.spacetraders.io"
   :service "443"
   :nowait t
   :tls-parameters (list 'gnutls-x509pki
                         :priority "NORMAL"
                         :hostname "api.spacetraders.io")
   :sentinel #'spacetraders/sentinel))

(defun spacetraders/sentinel (proc output)
  "Parse the jsons"
  (insert output))

(defun spacetraders/register (symbol faction)
  "Register a new agent"
  (let* ((json-body (json-encode (format "{\"symbol\": \"%s\", \"faction\": \"%s\"}" symbol faction)))
         (content-length (length json-body))
	 (process (spacetraders/open))
         (request (format "POST /v2/register HTTP/1.1\r\nHost: api.spacetraders.io\r\nAuthorization: Bearer %s\r\nContent-Type: application/json\r\nContent-Length: %d\r\n%s\r\n\r\n"
                          spacetraders/api-key content-length json-body)))
    (process-send-string process request)))

(spacetraders/register "PEPSI" "COSMIC")
(defun hex-to-binary (hex)
  (let ((decimal (string-to-number hex 16)))
    (if (= decimal 0)
        "0"
      (let ((binary ""))
        (while (> decimal 0)
          (setq binary (concat (if (= (% decimal 2) 0) "0" "1") binary))
          (setq decimal (/ decimal 2)))
        binary))))

About

my emacs configuration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published