From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: completion-at-point + semantic : erroneous error Date: Fri, 11 Oct 2019 13:34:48 -0400 Message-ID: References: <957ad127-0d84-69e3-49b6-9799975bd724@siege-engine.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="7974"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Emacs Development To: Eric Ludlam Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 11 20:51:13 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iJ00N-0001w1-Tc for ged-emacs-devel@m.gmane.org; Fri, 11 Oct 2019 20:51:12 +0200 Original-Received: from localhost ([::1]:55864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ00M-0002oY-Ke for ged-emacs-devel@m.gmane.org; Fri, 11 Oct 2019 14:51:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50665) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIyoY-0006xe-Uf for emacs-devel@gnu.org; Fri, 11 Oct 2019 13:34:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIyoX-0002w4-6s for emacs-devel@gnu.org; Fri, 11 Oct 2019 13:34:54 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:49686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIyoW-0002vm-Vd for emacs-devel@gnu.org; Fri, 11 Oct 2019 13:34:53 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1EF3D448DDA; Fri, 11 Oct 2019 13:34:52 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 52AD6448D56; Fri, 11 Oct 2019 13:34:50 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1570815290; bh=lwnX0SQI7uXLFJwjFOg7zsxIUVeyj1RN21cDAFGHtFA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=MMQ91/jxDIGuB+tTc1ZlQWwDTpzaBNWEojEepk4stYK2zll2LjNomaPdLXYdWn5YB 9z/BGKbJRsJDMCH1etDJwli3kdk3KBF4g+QoRmwU/huKza07Qnb5t8yBtbGY01zMP6 PEmpgXEl7rRHINmnYYRSJUNly42JpPVVcBC4qaFPw5TwUobpv5TxO7Yz+TjoxGuDOr WhF9sku5KEjrGynCsJh80dGJJHiqY/ErgdKH8ylYMxnTiJGo+5J1GAbxyTDmQKGsYM yhHOMrjzhtWim1e6bl3JrcsFsKZyhyEVjbYFa92e1ViwQgEoV7PB7QKlXHZZLFRLG5 jkqiORHSzpStw== Original-Received: from alfajor (modemcable157.163-203-24.mc.videotron.ca [24.203.163.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E0DB61202A1; Fri, 11 Oct 2019 13:34:49 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Fri, 11 Oct 2019 13:04:55 -0400") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 132.204.25.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:240897 Archived-At: > PS: It would also be good to replace uses of > define-overloadable-function with cl-defmethod, although the mapping > from one to the other is not immediate. The patch below is an attempt to do that for semantic-analyze-possible-completions. I'd be interested to hear your opinion on this (especially the with-mode-local part). Stefan diff --git a/lisp/cedet/semantic/analyze/complete.el b/lisp/cedet/semantic/analyze/complete.el index b471c0d1a1..193c975c47 100644 --- a/lisp/cedet/semantic/analyze/complete.el +++ b/lisp/cedet/semantic/analyze/complete.el @@ -63,7 +63,7 @@ semantic-analyze-tags-of-class-list ;;; MAIN completion calculator ;; ;;;###autoload -(define-overloadable-function semantic-analyze-possible-completions (context &rest flags) +(cl-defgeneric semantic-analyze-possible-completions (context &optional flags) "Return a list of semantic tags which are possible completions. CONTEXT is either a position (such as point), or a precalculated context. Passing in a context is useful if the caller also needs @@ -83,7 +83,9 @@ semantic-analyze-possible-completions * Argument to a function with type constraints. When called interactively, displays the list of possible completions in a buffer." - (interactive "d") + (semantic-analyze-possible-completions-default context flags)) + +(cl-defmethod semantic-analyze-possible-completions :around (context &rest flags) ;; In theory, we don't need the below since the context will ;; do it for us. ;;(semantic-refresh-tags-safe) @@ -93,8 +95,9 @@ semantic-analyze-possible-completions context (semantic-analyze-current-context context))) (ans (if (not context) - (error "Nothing to complete") - (:override)))) + (when (called-interactively-p 'any) + (error "Nothing to complete")) + (cl-call-next-method)))) ;; If interactive, display them. (when (called-interactively-p 'any) (with-output-to-temp-buffer "*Possible Completions*" diff --git a/lisp/cedet/semantic/bovine/make.el b/lisp/cedet/semantic/bovine/make.el index 3676c6972f..dbfa060b5d 100644 --- a/lisp/cedet/semantic/bovine/make.el +++ b/lisp/cedet/semantic/bovine/make.el @@ -32,9 +32,6 @@ (require 'semantic/analyze) (require 'semantic/dep) -(declare-function semantic-analyze-possible-completions-default - "semantic/analyze/complete") - ;;; Code: (define-lex-analyzer semantic-lex-make-backslash-no-newline "Detect and create a beginning of line token (BOL)." @@ -174,13 +171,13 @@ semantic-format-tag-uml-prototype This is the same as a regular prototype." (semantic-format-tag-prototype tag parent color)) -(define-mode-local-override semantic-analyze-possible-completions - makefile-mode (context) +(cl-defmethod semantic-analyze-possible-completions + (context &context (major-mode makefile-mode) &rest _) "Return a list of possible completions in a Makefile. Uses default implementation, and also gets a list of filenames." (require 'semantic/analyze/complete) (with-current-buffer (oref context buffer) - (let* ((normal (semantic-analyze-possible-completions-default context)) + (let* ((normal (cl-call-next-method)) (classes (oref context prefixclass)) (filetags nil)) (when (memq 'filename classes) diff --git a/lisp/cedet/semantic/grammar.el b/lisp/cedet/semantic/grammar.el index 813580ba6c..6767cb10fc 100644 --- a/lisp/cedet/semantic/grammar.el +++ b/lisp/cedet/semantic/grammar.el @@ -1914,13 +1914,15 @@ semantic-analyze-current-context context-return))) -(define-mode-local-override semantic-analyze-possible-completions - semantic-grammar-mode (context) +(cl-defmethod semantic-analyze-possible-completions + (context &context (major-mode semantic-grammar-mode) &rest _) "Return a list of possible completions based on CONTEXT." (require 'semantic/analyze/complete) (if (semantic-grammar-in-lisp-p) + ;; FIXME: Does the `let' make the `with-mode-local' redundant here? (with-mode-local emacs-lisp-mode - (semantic-analyze-possible-completions context)) + (let ((major-mode 'emacs-lisp-mode)) + (semantic-analyze-possible-completions context))) (with-current-buffer (oref context buffer) (let* ((prefix (car (oref context prefix))) (completetext (cond ((semantic-tag-p prefix) diff --git a/lisp/cedet/semantic/texi.el b/lisp/cedet/semantic/texi.el index 3a0050b920..510c4ea043 100644 --- a/lisp/cedet/semantic/texi.el +++ b/lisp/cedet/semantic/texi.el @@ -412,8 +412,8 @@ semantic-texi-command-completion-list ) "List of commands that we might bother completing.") -(define-mode-local-override semantic-analyze-possible-completions - texinfo-mode (context) +(cl-defmethod semantic-analyze-possible-completions + (context &context (major-mode texinfo-mode) &rest _) "List smart completions at point. Since texinfo is not a programming language the default version is not useful. Instead, look at the current symbol. If it is a command