From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: Try to understand the ora-company-number function again. Date: Thu, 21 Oct 2021 15:11:54 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2017"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 21 09:12:58 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdSG2-0000MN-K5 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 21 Oct 2021 09:12:58 +0200 Original-Received: from localhost ([::1]:48402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdSG1-0002Ez-MY for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 21 Oct 2021 03:12:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdSFE-0002Ec-B4 for help-gnu-emacs@gnu.org; Thu, 21 Oct 2021 03:12:08 -0400 Original-Received: from mail-ua1-x929.google.com ([2607:f8b0:4864:20::929]:33473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mdSFC-0000dS-7a for help-gnu-emacs@gnu.org; Thu, 21 Oct 2021 03:12:07 -0400 Original-Received: by mail-ua1-x929.google.com with SMTP id i15so11508091uap.0 for ; Thu, 21 Oct 2021 00:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=0tPBCdisJ1p9Civsi3TcCZXmV4EzIsUjuE9Ed3sIdak=; b=NUxDT5gvIKxGRUmEuE2vgByBZnK4Q/NoMvgmizJJ/xkeE3QAhNFw0jR4RJ0/eziap7 zooLPVoN6sU2FusdhwpPFsyBV90uW62Drr9lfXfIsFDTAnT3YV8I4B1QFU9FFe4typ18 /hcuneVagJSP8dfTTWweHkBozlZn7BzHcd9IZQOlz72SKk9BaciZwgf/SZ6AgFbWUBjI n+sbgDdOoBmFSewLFwwI57RtEE/PgzEZ6CzHXUJcBni6kjKv1Y7JZlj8K4+llgO0bUzq zZRKCr9RvQ6Pvnt7Ix/QazBwPMRAmCO5wmKcXNKT4PNH64k94yP3UPptEgCHZVQeSI27 xb1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0tPBCdisJ1p9Civsi3TcCZXmV4EzIsUjuE9Ed3sIdak=; b=pHyi6zGAP3L5FJMkTxRUPozSpJkE6zqJ8pil+kaUBaMS+dvVUoq+8LbACq7kbALPA3 Z4Mc+p6YLcwqwpEngFpQqYTpNjIdugHB/PB0sFatOJfletHiPfBWDZTwdnqqgKrp0Gr2 hcD3pjRIZILVLaunp7FvdJUe1uJ+4mt/AlynlUmSnrO//M6J2HDxnhnTIRydeDiXb6VQ eeep//QPSeBMKcXvJ13Y3CfUlwmVQX9Sk1lwCvr+WJrW/x8/d411reK7lobX26t1fO/k YAthfzwqdJt7LUy2Xja85EYi6CGG5qhbXCOXCu0pXIdq9Y88K7E9afeqwd0+b9/jDXix 5qmA== X-Gm-Message-State: AOAM533YPwayJj3oBflgSEgK0oDoW3i83xvowJmbVsx4wfqmOzPZiY89 Wvfq4HRibCJ0PKmInstJAj9YFB0o59mAzzupb57tVgfZRvpB94Kv X-Google-Smtp-Source: ABdhPJwgczM8YJOXL27yjdSsdCyodeWjeknbLmyFCdJUUYglnDKIgbCNFIgV4lHdzxlETSbQQqggigyedJgMuBOaK1g= X-Received: by 2002:a67:d91b:: with SMTP id t27mr4528019vsj.55.1634800325136; Thu, 21 Oct 2021 00:12:05 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::929; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x929.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133940 Archived-At: On Thu, Oct 21, 2021 at 2:54 PM Hongyi Zhao wrote: > > I try to understand the ora-company-number function [1] again: > > (defun ora-company-number () > "Forward to `company-complete-number'. > > Unless the number is potentially part of the candidate. > In that case, insert the number." > (interactive) > (let* ((k (this-command-keys)) > (re (concat "^" company-prefix k))) > (if (or (cl-find-if (lambda (s) (string-match re s)) > company-candidates) > (> (string-to-number k) > (length company-candidates)) > (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position))) > (self-insert-command 1) > (company-complete-number > (if (equal k "0") > 10 > (string-to-number k)))))) > > I've figured out all the intention of the above code snippet except > the following line: > > (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position) > > I can't understand why the regexp used here must be written in this > form. Any hints will be appreciated. Based on my tries, the following code snippet is enough: (defun ora-company-number () "Forward to `company-complete-number'. Unless the number is potentially part of the candidate. In that case, insert the number." (interactive) (let* ((k (this-command-keys)) (re (concat "^" company-prefix k))) (if (cl-find-if (lambda (s) (string-match re s)) company-candidates) (self-insert-command 1) (company-complete-number (if (equal k "0") 10 (string-to-number k))) ))) > [1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L22 > > Regards > -- > Assoc. Prof. Hongyi Zhao > Theory and Simulation of Materials > Hebei Vocational University of Technology and Engineering > No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province