From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: Re: arguments hint Date: Fri, 4 Jun 2004 16:33:06 +0300 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200406041633.06552.pogonyshev@gmx.net> References: <200406010011.16822.pogonyshev@gmx.net> <200406030022.35504.pogonyshev@gmx.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1086355666 13786 80.91.224.253 (4 Jun 2004 13:27:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 4 Jun 2004 13:27:46 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Jun 04 15:27:39 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BWEjT-0004ji-00 for ; Fri, 04 Jun 2004 15:27:39 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BWEjS-0003V1-00 for ; Fri, 04 Jun 2004 15:27:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BWEjq-0002N3-Me for emacs-devel@quimby.gnus.org; Fri, 04 Jun 2004 09:28:02 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BWEjc-0002JS-8t for emacs-devel@gnu.org; Fri, 04 Jun 2004 09:27:48 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BWEja-0002Iv-HT for emacs-devel@gnu.org; Fri, 04 Jun 2004 09:27:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BWEja-0002Il-FZ for emacs-devel@gnu.org; Fri, 04 Jun 2004 09:27:46 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.34) id 1BWEis-0002kP-VS for emacs-devel@gnu.org; Fri, 04 Jun 2004 09:27:03 -0400 Original-Received: (qmail 20368 invoked by uid 65534); 4 Jun 2004 13:26:37 -0000 Original-Received: from unknown (EHLO [195.50.12.117]) (195.50.12.117) by mail.gmx.net (mp023) with SMTP; 04 Jun 2004 15:26:37 +0200 X-Authenticated: #16844820 Original-To: emacs-devel@gnu.org User-Agent: KMail/1.6.52 In-Reply-To: <200406030022.35504.pogonyshev@gmx.net> Content-Disposition: inline X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24528 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24528 I made some experiments with `eldoc-mode' for C. Below are the results. The thing is very hackish and has many loose ends, but is already usable. It will print hints for the function of your project (i.e. it doesn't use any special tables for other functions) based on the tags. Contrary to what I expected, it works quite fast. Btw, as a side effect it opens extra buffers without being asked for it. This may be considered a serious drawback. Comments are welcome. Paul ;; To use: eval the below code and then `c-turn-on-eldoc-mode' ;; in a C buffer. (defvar c-eldoc-reserved-words (list "if" "else" "switch" "while" "for" "sizeof")) (defun c-turn-on-eldoc-mode () (interactive) (set (make-local-variable 'eldoc-print-current-symbol-info-function) 'c-print-current-symbol-info) (turn-on-eldoc-mode)) (defun c-function-and-argument (&optional limit) (let* ((return-point (point)) (literal-limits (c-literal-limits)) (literal-type (c-literal-type literal-limits))) (prog2 (when (eq literal-type 'string) (goto-char (car literal-limits)) (setq literal-type nil)) (if literal-type nil (c-save-buffer-state ((argument-index 1)) (while (or (eq (c-forward-token-2 -1 t limit) 0) (when (eq (char-before) ?\[) (backward-char) t)) (when (eq (char-after) ?,) (setq argument-index (1+ argument-index)))) (c-backward-syntactic-ws) (when (eq (char-before) ?\() (backward-char) (c-forward-token-2 -1) (when (looking-at "[a-zA-Z_][a-zA-Z_0-9]*") (cons (buffer-substring-no-properties (match-beginning 0) (match-end 0)) argument-index))))) (goto-char return-point)))) (defun c-format-arguments-string (arguments index) (let ((paren-pos (string-match "(" arguments)) (pos 0)) (when (string-match "(" arguments) (setq arguments (replace-regexp-in-string "\\\\?[[:space:]\\\n]" " " (substring arguments paren-pos)) arguments (replace-regexp-in-string "\\s-+" " " arguments) arguments (replace-regexp-in-string " *, *" ", " arguments) arguments (replace-regexp-in-string "( +" "(" arguments) arguments (replace-regexp-in-string " +)" ")" arguments)) (while (and (> index 1) pos (not (string= (substring arguments (+ pos 2) (+ pos 6)) "...)"))) (setq pos (string-match "," arguments (1+ pos)) index (1- index))) (when (and pos (setq pos (string-match "[^ ,()]" arguments pos))) (add-text-properties pos (string-match "[,)]" arguments pos) '(face bold) arguments)) arguments))) (defun c-print-current-symbol-info () (let* ((current-function-cons (c-function-and-argument (- (point) 1000))) (current-function (car current-function-cons)) (current-buffer (current-buffer)) (tag-buffer) (function-name-point) (arguments) (type-face 'font-lock-type-face)) (when (and current-function (not (member current-function c-eldoc-reserved-words))) (when (setq tag-buffer (find-tag-noselect current-function)) (prog2 (set-buffer tag-buffer) (when (search-forward current-function (line-end-position) t) (setq function-name-point (point)) (forward-sexp) (setq arguments (buffer-substring-no-properties function-name-point (point))) (goto-char function-name-point) (backward-char (length current-function)) (c-skip-ws-backward) (setq function-name-point (point)) (search-backward-regexp "[};/#]" (point-min) t) (if (= (char-after) ?#) (let ((is-define (looking-at "#[[:space:]]*define")) (preprocessor-point (point))) (while (prog2 (end-of-line) (= (char-before) ?\\) (forward-char))) (when (and is-define (> (point) function-name-point)) (goto-char preprocessor-point) (setq type-face 'font-lock-preprocessor-face))) (forward-char) (when (looking-back "//") (end-of-line))) (c-skip-ws-forward) (concat (propertize (buffer-substring-no-properties (point) function-name-point) 'face type-face) " " (propertize current-function 'face 'font-lock-function-name-face) " " (c-format-arguments-string arguments (cdr current-function-cons)))) (goto-char (mark t)) (set-buffer current-buffer))))))