From 90dc7b2d2f19944b5be9b19175db14a7ece35c99 Mon Sep 17 00:00:00 2001 From: gramanas Date: Wed, 20 Mar 2019 19:34:39 +0200 Subject: Add uniq flag for print_all and emacs frontend --- fcomp.el | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 fcomp.el (limited to 'fcomp.el') diff --git a/fcomp.el b/fcomp.el new file mode 100644 index 0000000..4e046d9 --- /dev/null +++ b/fcomp.el @@ -0,0 +1,108 @@ +;;; fcomp.el --- fcomp front-end -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Anastasis Grammenos + +;; Author: Anastasis Grammenos +;; Keywords: lisp +;; Version: 0.0.1 + +;; 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: + +;; Emacs front-end for fcomp. Get if from https://ubuntos.dynu.net/git/fcomp + +;;; Install: + +;; git clone https://ubuntos.dynu.net/git/fcomp && cd fcomp +;; make && sudo ln -s fcomp /usr/local/bin/fcomp # or mv + +;; In the emacs init file: +;; (add-to-list 'load-path "/your/custom/path") +;; (require 'fcomp) +;; (setq fcomp-path "/your/custom/path/fcomp") +;; (global-set-key (kbd "M-i") 'fcomp-autocomplete) + +;; or with use-package +;; (use-package fcomp +;; :load-path "/your/custom/path" +;; :bind (("M-i" . fcomp-autocomplete)) +;; :config +;; (setq fcomp-path "/your/custom/path/fcomp")) + + +;;; Code: + +(require 'ido) +(require 'subr-x) + +(defvar fcomp-path "/usr/local/bin/fcomp") +(defvar fcomp-min-word-length 3) +(defvar fcomp-extra-valid-chars "") +(defvar fcomp-extra-invalid-chars "") + +(defun pr () + (message "Status: %s" (process-status "fcomp"))) + +;; (thing-at-point 'word 'no-properties) +(defun fcomp-filter (proc str) + (let* ((fcomp-pre + (if (null (process-get proc 'input-word)) + nil + (format "%s" (process-get proc 'input-word))))) + ;; (enable-recursive-minibuffers t)) + ;; (setq result (substring result (* -1 (- (length result) (length word))) nil)) + (progn + (pr) + (setq result + (ido-completing-read + "Complete:" + (remove "" (split-string str "\n")) + nil nil + fcomp-pre)) + (if (null result) + nil + (insert + (string-remove-prefix + (if (null fcomp-pre) + (format "%s" "") + (format "%s" fcomp-pre)) + result)))))) + +(defun fcomp-autocomplete () + (interactive) + (fcomp--autocomplete (thing-at-point 'word 'no-properties))) + +(defun fcomp--autocomplete (word) + "Do stuff and ac" + (let ((term (if (null word) + (format "%s" "-au") + (format "%s" word))) + (input (buffer-substring-no-properties (point-min) (point-max)))) + (with-temp-buffer + (set-process-filter + (start-process + "fcomp" + nil + fcomp-path + "-w" (format "%s" fcomp-min-word-length) + "-F" input + "-v" (format "%s" fcomp-extra-valid-chars) + "-i" (format "%s" fcomp-extra-invalid-chars) + term) + #'fcomp-filter) + (process-put (get-process "fcomp") 'input-word word)))) + +(provide 'fcomp) +;;; fcomp.el ends here -- cgit v1.2.3