基于 ripgrep 的代码搜索和重构工具

比如我造了一个tex文本如下,你搜索 the 这个单词看看。只是一个例子,我的是投稿论文,不方便公开。

%%
%% This is file `sample-sigconf.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% samples.dtx  (with options: `sigconf')
%%
%% IMPORTANT NOTICE:
%%
%% For the copyright see the source file.
%%
%% Any modified versions of this file must be renamed
%% with new filenames distinct from sample-sigconf.tex.
%%
%% For distribution of the original source see the terms
%% for copying and modification in the file samples.dtx.
%%
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%
%% The first command in your LaTeX source must be the \documentclass command.
\documentclass[sigconf,review]{acmart}

%%
%% \BibTeX command to typeset BibTeX logo in the docs
\AtBeginDocument{%
  \providecommand\BibTeX{{%
      \normalfont B\kern-0.5em{\scshape i\kern-0.25em b}\kern-0.8em\TeX}}}

%% Rights management information.  This information is sent to you
%% when you complete the rights form.  These commands have SAMPLE
%% values in them; it is your responsibility as an author to replace
%% the commands and values with those provided to you when you
%% complete the rights form.
\setcopyright{acmcopyright}
\copyrightyear{2018}
\acmYear{2018}
\acmDOI{10.1145/1122445.1122456}

%% These commands are for a PROCEEDINGS abstract or paper.
\acmConference[Woodstock '18]{Woodstock '18: ACM Symposium on Neural
  Gaze Detection}{June 03--05, 2018}{Woodstock, NY}
\acmBooktitle{Woodstock '18: ACM Symposium on Neural Gaze Detection,
  June 03--05, 2018, Woodstock, NY}
\acmPrice{15.00}
\acmISBN{978-1-4503-XXXX-X/18/06}


%%
%% Submission ID.
%% Use this when submitting an article to a sponsored event. You'll
%% receive a unique submission ID from the organizers
%% of the event, and this ID should be used as the parameter to this command.
%% \acmSubmissionID{123-A56-BU3}

%%
%% The majority of ACM publications use numbered citations and
%% references.  The command \citestyle{authoryear} switches to the
%% "author year" style.
%%
%% If you are preparing content for an event
%% sponsored by ACM SIGGRAPH, you must use the "author year" style of
%% citations and references.
%% Uncommenting
%% the next command will enable that style.
%% \citestyle{acmauthoryear}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{float}

% remove ACM reference format
\settopmatter{printacmref=false}
\renewcommand\footnotetextcopyrightpermission[1]{} % removes footnote with conference information in first column
% remove copyright box
\setcopyright{none}
% remove doi
\makeatletter
\renewcommand\@formatdoi[1]{\ignorespaces}
\makeatother
\usepackage[utf8x]{inputenc}



%%
%% end of the preamble, start of the body of the document source.
\begin{document}

%%
%% The "title" command has an optional parameter,
%% allowing the author to define a "short title" to be used in page headers.

%%
%% The "author" command and its associated commands are used to define
%% the authors and their affiliations.
%% Of note is the shared affiliation of the first two authors, and the
%% "authornote" and "authornotemark" commands
%% used to denote shared contribution to the research.
% \author{Ben Trovato}
% \authornote{Both authors contributed equally to this research.}
% \email{[email protected]}
% \orcid{1234-5678-9012}
% \author{G.K.M. Tobin}
% \authornotemark[1]
% \email{[email protected]}
% \affiliation{%
% \institution{Institute for Clarity in Documentation}
% \streetaddress{P.O. Box 1212}
% \city{Dublin}
% \state{Ohio}
% \postcode{43017-6221}
% }

%   \author{Lars Th{\o}rv{\"a}ld}
%   \affiliation{%
%   \institution{The Th{\o}rv{\"a}ld Group}
%   \streetaddress{1 Th{\o}rv{\"a}ld Circle}
%   \city{Hekla}
%   \country{Iceland}}
%   \email{[email protected]}

%   \author{Valerie B\'eranger}
%   \affiliation{%
%   \institution{Inria Paris-Rocquencourt}
%   \city{Rocquencourt}
%   \country{France}
% }

%   \author{Aparna Patel}
%   \affiliation{%
%   \institution{Rajiv Gandhi University}
%   \streetaddress{Rono-Hills}
%   \city{Doimukh}
%   \state{Arunachal Pradesh}
%   \country{India}}

%   \author{Huifen Chan}
%   \affiliation{%
%   \institution{Tsinghua University}
%   \streetaddress{30 Shuangqing Rd}
%   \city{Haidian Qu}
%   \state{Beijing Shi}
%   \country{China}}

%   \author{Charles Palmer}
%   \affiliation{%
%   \institution{Palmer Research Laboratories}
%   \streetaddress{8600 Datapoint Drive}
%   \city{San Antonio}
%   \state{Texas}
%   \postcode{78229}}
%   \email{[email protected]}

%   \author{John Smith}
%   \affiliation{\institution{The Th{\o}rv{\"a}ld Group}}
%   \email{[email protected]}

%   \author{Julius P. Kumquat}
%   \affiliation{\institution{The Kumquat Consortium}}
%   \email{[email protected]}

%%
%%   By default, the full list of authors will be used in the page
%%   headers. Often, this list is too long, and will overlap
%%   other information printed in the page headers. This command allows
%%   the author to define a more concise list
%%   of authors' names for this purpose.
\renewcommand{\shortauthors}{Trovato and Tobin, et al.}

%%
%% The abstract is a short summary of the work to be presented in the
%% article.
\begin{abstract}
\end{abstract}

%%
%% The code below is generated by the tool at http://dl.acm.org/ccs.cfm.
%% Please copy and paste the code instead of the example below.
%%
% \begin{CCSXML}
%   <ccs2012>
%   <concept>
%   <concept_id>10010520.10010553.10010562</concept_id>
%   <concept_desc>Computer systems organization~Embedded systems</concept_desc>
%   <concept_significance>500</concept_significance>
%   </concept>
%   <concept>
%   <concept_id>10010520.10010575.10010755</concept_id>
%   <concept_desc>Computer systems organization~Redundancy</concept_desc>
%   <concept_significance>300</concept_significance>
%   </concept>
%   <concept>
%   <concept_id>10010520.10010553.10010554</concept_id>
%   <concept_desc>Computer systems organization~Robotics</concept_desc>
%   <concept_significance>100</concept_significance>
%   </concept>
%   <concept>
%   <concept_id>10003033.10003083.10003095</concept_id>
%   <concept_desc>Networks~Network reliability</concept_desc>
%   <concept_significance>100</concept_significance>
%   </concept>
%   </ccs2012>
% \end{CCSXML}

% \ccsdesc[500]{Computer systems organization~Embedded systems}
% \ccsdesc[300]{Computer systems organization~Redundancy}
% \ccsdesc{Computer systems organization~Robotics}
% \ccsdesc[100]{Networks~Network reliability}

%%
%% Keywords. The author(s) should pick words that accurately describe
%% the work being presented. Separate the keywords with commas.
% \keywords{datasets, neural networks, gaze detection, text tagging}

%% A "teaser" image appears between the author and affiliation
%% information and the body of the document, and typically spans the
%% page.
% \begin{teaserfigure}
%   \includegraphics[width=\textwidth]{sampleteaser}
%   \caption{Seattle Mariners at Spring Training, 2010.}
%   \Description{Enjoying the baseball game from the third-base
%   seats. Ichiro Suzuki preparing to bat.}
%   \label{fig:teaser}
% \end{teaserfigure}

%%
%% This command processes the author and affiliation and title
%% information and builds the first part of the formatted document.
\maketitle
\begin{figure}[!ht]
  \centering
  \begin{tabular}{@{}c@{ }c@{}}
    \includegraphics[width=0.23\textwidth]{images/comparison_in_the_wild//55476.png}\hspace{-3ex}&
    \includegraphics[width=0.23\textwidth]{images/comparison_in_the_wild/_/55476.png}
    \\[-0.2ex]
    \\[-0.2ex]
    \includegraphics[width=0.23\textwidth]{images/comparison_in_the_wild/2019/55476.png}\hspace{-3ex}&
    \includegraphics[width=0.23\textwidth]{images/comparison_in_the_wild//55476.png}
    \\[-0.2ex]
  \end{tabular}
  \label{fig:teaser}
  \vspace{-0.3cm}
\end{figure}




\begin{figure*}[!ht]
  \centering
  \includegraphics[width=1\textwidth]{images/SHdataset_example/dataset_example.pdf}
  \label{fig:exampleDataset}
\end{figure*}



the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the





the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the
the the

我的没有问题,建议你 emacs -Q 对比测试一下,估计是你的配置文件有问题。

emacs -Q搜索没有问题。我把个人搜索配置都注释掉了,还是有问题。可能是使用的Spacemacs的问题。

spacemacs 这种大而全的容易出现各种奇奇怪怪的兼容性问题,建议自己配置

感觉又是奇怪的 ansi-color 相关的问题,可以检查下 compilation-filter-hook 里面是不是挂了奇怪的 hook。

果真。

(defun spacemacs-visual/init-ansi-colors ()
 (add-hook 'compilation-filter-hook
             'spacemacs-visual//compilation-buffer-apply-ansi-colors))

我把这个注释掉就解决了。

1 个赞

使用spacemacs有两年了,遇到坑太多了。奶奶的,搞的心力交瘁。

1 个赞

嗯,我也怀疑就是这个,忘了把当时在 color-rg 里面的 issue 地址给出来了。doom-emacs 里面也有个类似的鬼。

windows10,昨天用着好好的,今天早上在用就会出现下面的错误

emacs -Q做了对比测试了吗?

做了,并且counsel-rg可以正常使用

发到issue吧,我一会盲修一下

好的,好的,好的

在windows下用cmdproxy确实很讨厌。可是怎么才能让emacs在windows下使用其他的shell来处理命令呢?我试了修改shell-file-name到cygwin的bash,可是运行rg还是无法识别中文。但是bash下运行rg就是可以识别中文的。难道subprocess默认使用cmdproxy了吗? 谢谢

用win10吧, win7 都不维护了

是用的win10啊,有什么差别吗?默认的还是cmdproxy不是吗?

我的解决办法是用grep-mode,hi-lock-mode自己写一个简单的rg搜索前端,但代码写得有问题,不好意思放出来,平时自己都不想用,搜索英文还是用counsel-rg,必须要搜索中文时才用自己写的这个,rg可以搜索中文,是emacs的问题

Win10 开Unicode support秒解一切Emacs相关中文编码问题(代价是某些游戏可能会出现编码不兼容)

以前在ivy的issue区里长篇大论过这个问题,然而似乎没什么人有兴趣

1 个赞

各位道友,我为什么我win10使用color-rg,总是报错:wrong type argument:stringp,nil这个错误呢?谁能告诉我问题在哪里啊。我系统都重新安装了,之前确定是可以使用的,并且我使用counsel-rg都是可以正常搜索中英文的。

你的问题是 ripgrep 运行的时候编码错误,导致进程输出的字符串无法被Emacs正常分割,你需要研究一下为啥你的编码有问题。

我从来不用Windows,没法复现你说的问题。