From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Glen Stark Newsgroups: gmane.emacs.help Subject: Help improving an elisp function Date: Thu, 02 Apr 2015 14:54:59 GMT Organization: Easynews - www.easynews.com Message-ID: <7LcTw.28088$kA6.5489@fx46.am4> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1427986530 29375 80.91.229.3 (2 Apr 2015 14:55:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Apr 2015 14:55:30 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 02 16:55:30 2015 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 1YdgWm-0005Ik-UX for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Apr 2015 16:55:29 +0200 Original-Received: from localhost ([::1]:58787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdgWm-0008FJ-Dr for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Apr 2015 10:55:28 -0400 Original-Path: usenet.stanford.edu!goblin1!goblin.stu.neva.ru!peer02.fr7!news.highwinds-media.com!post02.fr7!fx46.am4.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Original-Lines: 46 Original-X-Complaints-To: abuse@easynews.com X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. X-Received-Body-CRC: 3286607270 X-Received-Bytes: 2275 Original-Xref: usenet.stanford.edu gnu.emacs.help:211227 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:103509 Archived-At: Hi Everyone. Still trying to reach journeyman level with elisp. I've written a little something that helps my workflow, but it's pretty kludgy, and I'd like to get some feedback how to improve it. The code below makes finding and inserting a missing include a lot easier: F9: goes to the definition (via ggtags) of thing-at-point. F10: copies the buffer name, closes the buffer, and inserts the missing include file. But it's pretty awful. What I'd really like to do is have one function that looks up the buffer-name in question, and inserts the include statement, without jumping there. Also, I had originally had the line (seq gas-cpp-include-path (buffer- file-name)) in the find-what-provides function, but that wound up giving me the path to the buffer I was starting in, not the one that ggtags-find- definition took me to. Can someone let me know what's going on there? Is the buffer only being updated after the function exits? Many thanks. Here's the code: (require ggtags) (setq gas-cpp-include-path) (defun find-what-provides () (interactive) (ggtags-find-definition (thing-at-point `symbol)) ) (defun insert-missing-include () (interactive) (setq gas-cpp-include-path (buffer-file-name)) (kill-buffer) (beginning-of-buffer) (while (re-search-forward "#include \".*\"" nil t)) (insert (concat "\n#include \"" (file-name-nondirectory gas-cpp-include- path) "\"\n")) ) (global-set-key (kbd "") 'find-what-provides) (global-set-key (kbd "") 'insert-missing-include)