From: bvraghav@iitk.ac.in (B.V. Raghav)
To: Drew Adams <drew.adams@oracle.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: C Headers completion candidates
Date: Sun, 17 Jul 2016 14:10:57 +0530 [thread overview]
Message-ID: <87twfohd2e.fsf@ram.bvr.dp.lan> (raw)
In-Reply-To: <d8913689-82a7-441a-9b90-e369b770b1b3@default> (Drew Adams's message of "Thu, 14 Jul 2016 07:27:19 -0700 (PDT)")
Drew Adams <drew.adams@oracle.com> writes:
[snip]
>
>> Step 1. Identifying the context
>> --- Example
>> #include <vec|>
>> ---
>> `|' 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 <vector>,
<utility>, <unordered_map>, <iterator> --- 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 <boost/algorithm/string/case_conv.hpp> 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
next prev parent reply other threads:[~2016-07-17 8:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-14 4:51 C Headers completion candidates B.V. Raghav
2016-07-14 13:02 ` Stefan Monnier
2016-07-14 14:27 ` Drew Adams
2016-07-17 8:40 ` B.V. Raghav [this message]
2016-07-17 15:02 ` Drew Adams
2016-07-18 3:07 ` B.V. Raghav
2016-07-18 5:17 ` Drew Adams
2016-07-18 11:21 ` B.V. Raghav
2016-07-18 14:17 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87twfohd2e.fsf@ram.bvr.dp.lan \
--to=bvraghav@iitk.ac.in \
--cc=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).