From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: bvraghav@iitk.ac.in (B.V. Raghav) Newsgroups: gmane.emacs.help Subject: Re: C Headers completion candidates Date: Sun, 17 Jul 2016 14:10:57 +0530 Organization: Indian Institute of Technology, Kanpur Message-ID: <87twfohd2e.fsf@ram.bvr.dp.lan> References: <87k2gozusa.fsf@ram.bvr.dp.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1468744912 31432 80.91.229.3 (17 Jul 2016 08:41:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 17 Jul 2016 08:41:52 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 17 10:41:48 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bOhdw-0007Li-CQ for geh-help-gnu-emacs@m.gmane.org; Sun, 17 Jul 2016 10:41:44 +0200 Original-Received: from localhost ([::1]:40607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bOhdu-0008BT-Um for geh-help-gnu-emacs@m.gmane.org; Sun, 17 Jul 2016 04:41:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bOhdV-0008BN-Ci for help-gnu-emacs@gnu.org; Sun, 17 Jul 2016 04:41:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bOhdR-0004bC-Fq for help-gnu-emacs@gnu.org; Sun, 17 Jul 2016 04:41:17 -0400 Original-Received: from mail3.iitk.ac.in ([202.3.77.190]:57537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bOhdQ-0004Zi-Oy for help-gnu-emacs@gnu.org; Sun, 17 Jul 2016 04:41:13 -0400 Original-Received: from smtp.cc.iitk.ac.in (smtp.cc.iitk.ac.in [172.31.1.22]) by mail3.iitk.ac.in (Postfix) with ESMTP id A17B010000AB; Sun, 17 Jul 2016 14:10:57 +0530 (IST) Original-Received: from ram.bvr.dp.lan.iitk.ac.in (unknown [172.20.240.119]) (Authenticated sender: bvraghav) by smtp.cc.iitk.ac.in (Postfix) with ESMTPA id 9CACA48; Sun, 17 Jul 2016 14:10:57 +0530 (IST) Importance: normal In-Reply-To: (Drew Adams's message of "Thu, 14 Jul 2016 07:27:19 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 202.3.77.190 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110873 Archived-At: Drew Adams writes: [snip] > >> Step 1. Identifying the context >> --- Example >> #include >> --- >> `|' represents the cursor here >> I think I can code the regexp here I have no experience with using using the point so far inside of an interactive function. But I think it is do-able. Albeit, not with a regexp, but somehow. I leave it for another rainy day. [snip] > >> Step 2. Set of completion candidates >> Search the $INCLUDE environment variable, with `visited' flags on the >> folders that have been visited; and create the set of completion >> candidates, one in a line I realised the environment variables, that I had initialized in ~/.bashrc are not avaliable at the X server environment (probably, not even with ~/.profile). So I hard coded the list, and copy-pasted from the bashrc. (require 'cl-lib) (defun c-include-path() (cl-reduce #'append (mapcar #'parse-colon-path `("/usr/include/c++/5:/usr/include/c++/4.9" ,(format "%s/usr/include" (getenv "HOME")) "/usr/include:/usr/local/include:/usr/include/x86_64-linux-gnu")))) The order of directories is important here. May be it looks dirty, but work for now. Then, I retrieved all the files at first level depth of each of this list. And mapped all the directory elements to their absolute paths. ;; (c-include-path) (defun c-include-libs-raw(path) (cl-reduce #'append (mapcar (lambda (x) (mapcar (lambda (y) (let ((long-y (format "%s%s" x y))) (if (file-accessible-directory-p long-y) long-y y))) (when (file-accessible-directory-p x) (directory-files x)))) path))) Then I removed the unnecessary files (defun sanitize-dir-read (path-list) (cl-remove-if (lambda(x) (or (string-suffix-p "." x) (string-suffix-p "~" x) (string-prefix-p "_" x))) path-list)) [snip] > >> Step 3. Tell Icicles to invoke these set of completion candidates, >> when the context is active. How? I do not know. [snip] Here I used the completion in two steps. Though not as `smart', or seamless; but works (defun c-header() (let* ((include-path-list (c-include-path)) (lib-name-list (sanitize-dir-read (c-include-libs-raw (c-include-path)))) (selected-path (completing-read "Library: " lib-name-list)) (final-path (if (file-accessible-directory-p selected-path) (read-file-name "Header: " (format "%s/" selected-path)) selected-path)) (inclusive-path (which-c-prefix final-path include-path-list)) (include-file-name (file-relative-name final-path inclusive-path))) include-file-name)) First completing the name from the files (and folders) at first level. Then using the response to aid the next level completion. Most C-libraries, that I require, are first class citizens, and are completed within the first level of completion. Like , , , --- all completed using the same set of functions above, work like charm with Icicles. For other libraries, I have to use the name of the library and S-TAB, like This is a little longer, but way faster (and cleaner) than what I used to do earlier. Either, I copy pasted from the earlier files, or used a snippet. Way forward, I want to implement this: 1. Implement a list of completions, at the user level; quite like persistent completions; a. Any completion, after being pruned for prefix (before being returned), goes as into the list of completions, without duplicacy. b. This list is read, and appened to the lib-name-list; before the first completion is invoked. Thanks, r -- (B.V. Raghav) Ph.D. Student, Design Programme, IIT Kanpur