Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ Keybinding | Description

Auto-complete/Company:

Keybinding | Description
-------------------|-----------------------------------------------------------
<kbd>C-.</kbd> | Force trigger auto-complete/company-complete.
<kbd>ESC</kbd> | Abort auto-complete/company-complete.
Keybinding | Description
------------------------------------|------------------------------------------------------------------------------------------
<kbd>C-.</kbd> | Force trigger auto-complete/company-complete.
<kbd>ESC</kbd> | Abort auto-complete/company-complete.
<kbd>C-o</kbd> or <kbd>C-\\</kbd> | Company only: switch to other backend (`company-other-backend`)
<kbd>C-M-h</kbd> | Company only: show doc buffer for current candidate (`company-show-doc-buffer`)
<kbd>C-M-v</kbd> | Company only: scroll doc buffer up (`scroll-other-window`)
<kbd>C-M-S-v</kbd> | Company only: scroll doc buffer down (`scroll-other-window-down`)
<kbd>C-h</kbd> or <kbd><f1></kbd> | Company only: show quick help for current candidate (`company-posframe-quickhelp-toggle`)
<kbd>C-S-v</kbd> or <kbd><f2></kbd> | Company only: scroll quick help up (`company-posframe-quickhelp-scroll-up`)
<kbd>M-V</kbd> or <kbd><f3></kbd> | Company only: scroll quick help down (`company-posframe-quickhelp-scroll-down`)

Tip: if you are looking for a particular key and you know it starts with a
given prefix, type the prefix followed by <kbd>C-h</kbd>: Emacs will display
Expand Down
107 changes: 48 additions & 59 deletions modules/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

;;; Commentary:
;;
;; ----------------- -------------------------------------------------------
;; Key Definition
;; ----------------- -------------------------------------------------------
;; C-. Force trigger company-complete.
;; C-o or C-\ Switch to other backend (`company-other-backend').
;; C-M-h Show doc buffer for current candidate (`company-show-doc-buffer').
;; C-M-v Scroll doc buffer up (`scroll-other-window').
;; C-M-S-v Scroll doc buffer down ('scroll-other-window-down').
;; C-h or <f1> Show quick help for current candidate (`company-posframe-quickhelp-toggle').
;; C-S-v or <f2> Scroll quick help up (`company-posframe-quickhelp-scroll-up').
;; M-V or <f3> Scroll quick help down (`company-posframe-quickhelp-scroll-down').

;;; Code:
(eval-when-compile
Expand All @@ -11,15 +22,12 @@
(exordium-require 'init-git)

(require 'cl-lib)

(when (version< "29" emacs-version)
(exordium-require 'init-forge))
(require 'compat)

(use-package company
:diminish "CA"
:demand t
:commands (company-other-backend
company-abort)
:commands (company-other-backend)
:custom
(company-idle-delay nil)
(company-files-exclusions '(".git/" ".gitignore" ".gitmodules" ".DS_Store"
Expand All @@ -37,7 +45,9 @@

:bind
(("C-." . #'company-complete)
("C-c C-\\" . #'company-other-backend)))
:map company-active-map
("C-\\" . #'company-other-backend)
("C-o" . #'company-other-backend)))

(use-package company
:diminish "CA"
Expand All @@ -46,61 +56,9 @@
:commands (company-begin-backend)
:functions (exordium--company-conventional-commits-type-p)
:init
(use-package forge-core
:ensure forge
:defer t
:autoload (forge-get-repository))

(use-package git-commit
:ensure magit)

(defun exordium-company-assignees (command &optional arg &rest _ignored)
"A `company-mode' backend for assigneees in `forge-mode' repository."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'exordium-company-assignees))
(prefix
(save-match-data
(when (and (or (bound-and-true-p git-commit-mode)
(derived-mode-p 'forge-post-mode
'git-commit-elisp-text-mode))
(forge-get-repository 'full)
(looking-back
(rx "@"
(zero-or-one
(group alphanumeric
(repeat 0 38
(or alphanumeric
(seq (any "-/") alphanumeric))))))
(max (- (point) 40)
(line-beginning-position))))
;; IDK how to match end of a 'symbol' that is equal to an "@" or is
;; equal to "@foo" in neither `git-commit-mode' nor
;; `forge-post-mode'. Hence it's handled manually. The
;; `looking-back' above matches an "@" or an "@foo". When it was the
;; latter there was a match in group 1. Now, check if this is at
;; the very end of the "@" or "@foo". Note that "@<point>@" also
;; matches. Probably a few other characters, substituting the second
;; "@" in latter pattern, would also give a positive result. Yet, in
;; such a case the `match' is "", so that's all fine - all
;; candidates will be shown.
(when (or (save-match-data (looking-at "\\W"))
(= (point) (point-max)))
(cons (or (match-string 1) "") t)))))
(candidates (when-let* ((repo (forge-get-repository :tracked?))
((slot-exists-p repo 'assignees))
((slot-boundp repo 'assignees))
(assignees (oref repo assignees)))
(cl-remove-if-not
(lambda (assignee)
(string-prefix-p arg assignee))
(mapcar (lambda (assignee)
(propertize (cadr assignee)
'full-name (caddr assignee)))
assignees))))
(annotation (when-let* ((assignee (get-text-property 0 'full-name arg)))
(format " [%s]" assignee)))))

(defconst exordium--company-conventional-commits-types
(list
;; From Conventional Commits: https://www.conventionalcommits.org
Expand Down Expand Up @@ -264,16 +222,47 @@ See https://www.conventionalcommits.org for details."

:config
;; This is block is deferred , so this backed will end up first
(add-to-list 'company-backends 'exordium-company-assignees)
(add-to-list 'company-backends 'exordium-company-conventional-commits))

(when (version< "29" emacs-version) ;; Since Emacs-29
(use-package company-forge
:config
(company-forge-icons-mode) ;; Display icons
(advice-add #'forge--pull ;; Reset cache after forge pull
:filter-args #'company-forge-reset-cache-after-pull)
(add-to-list 'company-backends 'company-forge)
(add-hook 'completion-at-point-functions
#'company-forge-completion-at-point-function)))

(use-package company-statistics
:after (company)
:config
(company-statistics-mode)
(add-to-list 'company-transformers
'company-sort-by-backend-importance 'append))

(use-package company-posframe
:demand t
:diminish
:init
(use-package company
:defer t
:commands (company-show-doc-buffer))
:commands (company-posframe-quickhelp-toggle
company-posframe-quickhelp-scroll-down
company-posframe-quickhelp-scroll-up)
:bind
(:map company-posframe-active-map
("C-h" . #'company-posframe-quickhelp-toggle)
("C-M-h" . #'company-show-doc-buffer)
("C-S-v" . #'company-posframe-quickhelp-scroll-up)
("M-V" . #'company-posframe-quickhelp-scroll-down))
:custom
(company-posframe-quickhelp-delay 0.2)
(company-posframe-quickhelp-x-offset 5)
:config
(company-posframe-mode 1))

(provide 'init-company)

;;; init-company.el ends here
2 changes: 2 additions & 0 deletions modules/init-desktop.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
(require 'savehist)
(require 'desktop)

(add-to-list 'desktop-minor-mode-table '(company-posframe-mode nil))

(defun exordium--restore-desktop ()
"Restore desktop."
(setq desktop-path (list user-emacs-directory))
Expand Down
Loading