which-function-mode

本文介绍如何利用Emacs内置功能which-function-mode快速显示当前光标所在位置的类或方法名称,包括自定义显示位置及未知定义时的提示信息。

每个开发者应该偶尔会遇到这么一种情况吧:你正在查看一个类或方法的定义代码,这时候你想看看这个类/方法的名称是什么,但是很有可能这个类/方法的名称并同时也没有显示在编辑区中. 当然,你可以往上拖动滚动条然后查看一下类/方法的名称,但其实有一个更加简便的方法,那就是使用Emacs内建的which-function-mode.

当开启了which-function-mode后,你会在buffer modeline的中间位置看到光标所在处的代码所表示的定义的名称.

开启which-function-mode的方式很简单:

(which-function-mode)

这样就会对所有支持which-function-mode的major mode都开启该功能了.

若你只想在特定的几个major mode下开启该功能,可以这样做:

(add-to-list 'which-func-modes 'ruby-mode)      
(add-to-list 'which-func-modes 'emacs-lisp-mode)

默认情况下,当which-function-mode不能检测到定义的名称时,会显示`???`. 但你也可以通过下面的语句来更改这个显示方式:

(setq which-func-unknown "n/a")

那么,如果你希望把定义的名称显示在buffer的header-line而不是modeline该怎么办呢? 下面的代码能做到这一点(由Sebastian Wiesner提供)

;; Show the current function name in the header line                                (which-function-mode)                                                               
(setq-default header-line-format                                                    
              '((which-func-mode ("" which-func-format " "))))                      
(setq mode-line-misc-info                                                           
      ;; We remove Which Function Mode from the mode line, because it's mostly
      ;; invisible here anyway.                                               
      (assq-delete-all 'which-func-mode mode-line-misc-info))


### Cross-Correlation Function (CCF) in Time Series Analysis and Signal Processing In time series analysis and signal processing, the cross-correlation function (CCF) is a measure of similarity between two signals as a function of the displacement of one relative to the other. This technique helps identify how much one signal resembles another at different points in time. The mathematical definition of the discrete cross-correlation \( R_{xy}(\tau) \) between two sequences \( x[n] \) and \( y[n] \), where \( n \in Z \), can be expressed as follows: \[ R_{xy}[\tau] = E\left[(x[n+\tau]-\mu_x)(y[n]-\mu_y)\right], \] where \( E[] \) denotes expectation value, \( \mu_x \) and \( \mu_y \) are means of \( x[n] \) and \( y[n] \)[^1]. For practical implementation purposes, especially when dealing with finite-length data sets, this formula often simplifies into summing products over all available pairs separated by lag \( \tau \): \[ R_{xy}[\tau]=\sum _{n=0}^{N-\tau -1}(x[n+\tau ]-{\bar {x}})(y[n]-{\bar {y}}). \] Here’s an example Python code snippet demonstrating computation of CCF using NumPy library functions `numpy.correlate` which computes linear correlation coefficients directly from input arrays without explicit mean subtraction required beforehand since it internally handles normalization process effectively: ```python import numpy as np def compute_ccf(x, y): """Compute cross-correlation function.""" ccf_values = [] # Compute zero-padding length based on maximum possible shift pad_len = max(len(x), len(y)) # Zero-pad both inputs equally so they match lengths after shifting xpadded = np.pad(x, (pad_len,), mode='constant') ypadded = np.pad(y, (pad_len,), mode='constant') for tau in range(-len(x)+1, len(y)): shifted_x = np.roll(xpadded, tau)[:len(ypadded)] # Calculate product term only within valid overlap region prod_term = shifted_x * ypadded # Sum up non-zero elements corresponding to actual overlaps corr_val = np.sum(prod_term[np.nonzero(prod_term)]) ccf_values.append(corr_val) return np.array(ccf_values) # Example usage: if __name__ == "__main__": import matplotlib.pyplot as plt t = np.linspace(0, 5, num=500) sig1 = np.sin(t*2*np.pi/0.87)*np.exp(-t/3.) sig2 = np.cos((t-.4)*2.*np.pi/.9)*np.exp(-(t-.4)/2.) result = compute_ccf(sig1, sig2) fig, ax = plt.subplots() lags = list(range(-len(sig1)+1,len(sig2))) ax.plot(lags, result) ax.set_xlabel('Lag') ax.set_ylabel('Cross Correlation Value') plt.show() ``` This script generates sine waves modulated exponentially decaying envelopes representing typical real-world noisy measurements; calculates their pairwise correlations across various temporal offsets visualized through plotting results against respective delays indicating peaks whenever matching patterns align closely together suggesting strong association existing thereat.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值