diff --git a/.gitignore b/.gitignore index 1377554..c18dd8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -*.swp +__pycache__/ diff --git a/install.py b/install.py index e69de29..f8d0902 100755 --- a/install.py +++ b/install.py @@ -0,0 +1 @@ +from subprocess import call diff --git a/lain/.emacs.d/config.org b/lain/.emacs.d/config.org index 2eab325..081138b 100644 --- a/lain/.emacs.d/config.org +++ b/lain/.emacs.d/config.org @@ -57,12 +57,24 @@ Shut up, emacs. (setq ring-bell-function 'ignore) #+END_SRC -** Show relative line numbers +** Relative line numbers +Use the default emacs relative line numbers, but switch to absolute lines when in insert mode. #+BEGIN_SRC emacs-lisp -(unless (version< emacs-version "26.1") -(setq display-line-numbers-type 'relative) (setq linum-format " %3d ") -(global-display-line-numbers-mode t)) +(setq-default display-line-numbers 'relative + display-line-numbers-widen t + display-line-numbers-current-absolute t) + +(defun foltz-relative-numbers () + (setq-local display-line-numbers 'relative)) + +(defun foltz-absolute-numbers () + (setq-local display-line-numbers t)) + +(add-hook 'evil-insert-state-entry-hook #'foltz-absolute-numbers) +(add-hook 'evil-insert-state-exit-hook #'foltz-relative-numbers) + +(global-display-line-numbers-mode t) #+END_SRC ** y or n prompts @@ -158,6 +170,7 @@ See [[https://github.com/noctuid/general.el#which-key-integration][here]] for wh :prefix "SPC" "m" '(:ignore t :which-key "major-mode...") "o" '(:ignore t :which-key "org-mode...") + "p" '(:ignore t :which-key "projectile-mode...") "g" '(:ignore t :which-key "git...") "h" '(:ignore t :which-key "help...") "b" '(:ignore t :which-key "buffer...") @@ -181,6 +194,9 @@ See [[https://github.com/noctuid/general.el#which-key-integration][here]] for wh :prefix "SPC o") #+END_SRC +**** p - projectile-mode +Since we will be binding the entire projectile-mode +keymap to this, we don't actually need a definer. **** g - git #+BEGIN_SRC emacs-lisp (general-create-definer foltz-git-def @@ -591,6 +607,17 @@ Keybinds [here](https://github.com/emacs-evil/evil-magit) :after evil)) #+END_SRC +** Projects +Projectile provides project-level features like +make shortcuts and file switching +#+BEGIN_SRC emacs-lisp +(use-package projectile + :bind-keymap + :general + (foltz-leader-def + :states 'normal + "p" '(:keymap projectile-command-map))) +#+END_SRC ** Languages *** Fish Beter editing of scripts for the fish shell diff --git a/menu.py b/menu.py new file mode 100755 index 0000000..542bacd --- /dev/null +++ b/menu.py @@ -0,0 +1,80 @@ +#!/usr/bin/python + +import curses +from curses import panel + +class Menu(object): + def __init__(self, stdscreen, items): + self.window = stdscreen.subwin(0, 0) + self.window.keypad(1) + self.panel = panel.new_panel(self.window) + self.panel.hide() + panel.update_panels() + + self.position = 0 + self.items = items + self.items.append(('exit', 'exit')) + + def navigate(self, n): + self.position += n + self.position %= len(self.items) + + def display(self): + self.panel.top() + self.panel.show() + self.window.clear() + + while True: + self.window.refresh() + curses.doupdate() + for index, item in enumerate(self.items): + if index == self.position: + mode = curses.A_REVERSE + else: + mode = curses.A_NORMAL + + msg = '%d. %s' % (index, item[0]) + self.window.addstr(1+index, 1, msg, mode) + + key = self.window.getch() + + if key in [curses.KEY_ENTER, ord('\n')]: + if self.position == len(self.items)-1: + break + else: + self.items[self.position][1]() + + elif key == curses.KEY_UP: + self.navigate(-1) + + elif key == curses.KEY_DOWN: + self.navigate(1) + + self.window.clear() + self.panel.hide() + panel.update_panels() + curses.doupdate() + +class App(object): + def __init__(self, stdscreen): + self.screen = stdscreen + curses.curs_set(0) + + submenu_items = [ + ('beep', curses.beep), + ('flash', curses.flash) + ] + submenu = Menu(self.screen, submenu_items) + + main_menu_items = [ + ('beep', curses.beep), + ('flash', curses.flash), + ('submenu', submenu.display) + ] + main_menu = Menu(self.screen, main_menu_items) + main_menu.display() + +if __name__ == '__main__': + curses.wrapper(App) + + diff --git a/parse.py b/parse.py index 508a582..373ebce 100755 --- a/parse.py +++ b/parse.py @@ -1,30 +1,34 @@ #!/usr/bin/python +import re class Package: def __init__(self, line): self.type = line[0] self.name = line[1] self.script = line[2] if len(line) == 3 else None - type = None - name = None - script = None + @staticmethod + def is_package_line(line): + return re.match(r"^[^*]+", line[0]) class Category: def __init__(self, line): self.name = ' '.join(line[1:]) self.packages = [] - name = '' - packages = [] + @staticmethod + def is_category_line(line): + return re.match(r"^\*+", line[0]) + +def split(lines): + return list(map(lambda line: line.rstrip().split(' '), lines)) def parse_package_listing(file): f = open(file, 'r') - lines = list(map(lambda l: l.rstrip().split(' '), f.readlines())) categories = [] category = None - for line in lines: - if line[0].startswith('*'): + for line in split(f.readlines()): + if Category.is_category_line(line): category = Category(line) categories.append(category) - elif len(line[0]) != 0: + elif Package.is_package_line(line): category.packages.append(Package(line)) return categories diff --git a/test.py b/test.py new file mode 100755 index 0000000..42fc7cb --- /dev/null +++ b/test.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +import parse + +categories = parse.parse_package_listing('packages.org') + +for category in categories: + print(category.name) + for package in category.packages: + print('- ' + package.name)