summaryrefslogtreecommitdiff
path: root/lisp/ffap.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2016-12-30 15:31:01 +0900
committerTino Calancha <tino.calancha@gmail.com>2016-12-30 15:31:01 +0900
commitc336420d9f2ffe5270d7deec360d84e1f45b4a55 (patch)
treeedbab7c255781c4963da04896c90bc706c90c104 /lisp/ffap.el
parent9672f2c916b5909cc5836f67edc4d66842cce7cd (diff)
downloademacs-c336420d9f2ffe5270d7deec360d84e1f45b4a55.tar.gz
ffap-string-at-point: Limit max length of active region
Prevents that 'ffap-guesser' waste time checking large strings which are likely not valid candidates (Bug#25243). * lisp/ffap.el (ffap-max-region-length): New variable. (ffap-string-at-point): Use it. * test/lisp/ffap-tests.el: New test suite. (ffap-tests-25243): Add test for this bug.
Diffstat (limited to 'lisp/ffap.el')
-rw-r--r--lisp/ffap.el25
1 files changed, 18 insertions, 7 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 3d7cebadcf6..99bb65faafe 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -203,6 +203,11 @@ Sensible values are nil, \"news\", or \"mailto\"."
)
:group 'ffap)
+(defvar ffap-max-region-length 1024
+ "Maximum active region length.
+When the region is active and larger than this value,
+`ffap-string-at-point' returns an empty string.")
+
;;; Peanut Gallery (More User Variables):
;;
@@ -1101,8 +1106,10 @@ MODE (defaults to value of `major-mode') is a symbol used to look up
string syntax parameters in `ffap-string-at-point-mode-alist'.
If MODE is not found, we use `file' instead of MODE.
If the region is active, return a string from the region.
-Sets the variable `ffap-string-at-point' and the variable
-`ffap-string-at-point-region'."
+Set the variable `ffap-string-at-point' and the variable
+`ffap-string-at-point-region'.
+When the region is active and larger than `ffap-max-region-length',
+return an empty string, and set `ffap-string-at-point-region' to '(1 1)."
(let* ((args
(cdr
(or (assq (or mode major-mode) ffap-string-at-point-mode-alist)
@@ -1119,11 +1126,15 @@ Sets the variable `ffap-string-at-point' and the variable
(save-excursion
(skip-chars-forward (car args))
(skip-chars-backward (nth 2 args) pt)
- (point)))))
- (setq ffap-string-at-point
- (buffer-substring-no-properties
- (setcar ffap-string-at-point-region beg)
- (setcar (cdr ffap-string-at-point-region) end)))))
+ (point))))
+ (region-len (- (max beg end) (min beg end))))
+ (if (and (natnump ffap-max-region-length)
+ (< region-len ffap-max-region-length)) ; Bug#25243.
+ (setf ffap-string-at-point-region (list beg end)
+ ffap-string-at-point
+ (buffer-substring-no-properties beg end))
+ (setf ffap-string-at-point-region (list 1 1)
+ ffap-string-at-point ""))))
(defun ffap-string-around ()
;; Sometimes useful to decide how to treat a string.