This is like 'filename', but is a full path, and is nil if the file
doesn't exist.
-*** New 'thing-at-point' target: 'list-or-string'.
-This is like 'list, but if point is inside a string that's enclosed in
-the list, it returns the enclosed string and not the enclosing list.
-
-This is like 'list', but also prefers to find of any enclosing string.
+*** New 'thing-at-point' target: 'string'.
+If point is inside a string, it returns the enclosed string.
+++
*** New variable 'thing-at-point-provider-alist'.
`(menu-item "Defun"
,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'defun))
:help "Mark the defun at click for a subsequent cut/copy"))
- (define-key-after submenu [mark-list-or-string]
- `(menu-item ,(if (nth 8 (save-excursion
- (syntax-ppss (posn-point (event-end click)))))
- "String" "List")
- ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'list-or-string))
- :help "Mark list or string at click for a subsequent cut/copy"))
+ (define-key-after submenu [mark-list]
+ `(menu-item "List"
+ ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'list))
+ :help "Mark the list at click for a subsequent cut/copy"))
+ (when (let ((pos (posn-point (event-end click))))
+ (or (eq (char-syntax (char-after pos)) ?\")
+ (nth 3 (save-excursion (syntax-ppss pos)))))
+ (define-key-after submenu [mark-string]
+ `(menu-item "String"
+ ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'string))
+ :help "Mark the string at click for a subsequent cut/copy")))
(define-key-after submenu [mark-line]
`(menu-item "Line"
,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'line))
(put 'line 'beginning-op
(lambda () (if (bolp) (forward-line -1) (beginning-of-line))))
-;; Sexps
+;; Strings
+
+(put 'string 'bounds-of-thing-at-point 'thing-at-point-bounds-of-string-at-point)
+
+(defun thing-at-point-bounds-of-string-at-point ()
+ "Return the bounds of the string at point.
+Prefer the enclosing string with fallback on sexp at point.
+\[Internal function used by `bounds-of-thing-at-point'.]"
+ (save-excursion
+ (let ((ppss (syntax-ppss)))
+ (if (nth 3 ppss)
+ ;; Inside the string
+ (ignore-errors
+ (goto-char (nth 8 ppss))
+ (cons (point) (progn (forward-sexp) (point))))
+ ;; At the beginning of the string
+ (if (eq (char-syntax (char-after)) ?\")
+ (let ((bound (bounds-of-thing-at-point 'sexp)))
+ (and bound
+ (<= (car bound) (point)) (< (point) (cdr bound))
+ bound)))))))
(defun in-string-p ()
"Return non-nil if point is in a string."
(beginning-of-defun)
(nth 3 (parse-partial-sexp (point) orig)))))
+;; Sexps
+
(defun thing-at-point--end-of-sexp ()
"Move point to the end of the current sexp."
(let ((char-syntax (syntax-after (point))))
(put 'list 'bounds-of-thing-at-point 'thing-at-point-bounds-of-list-at-point)
-(defun thing-at-point-bounds-of-list-at-point (&optional escape-strings no-syntax-crossing)
+(defun thing-at-point-bounds-of-list-at-point ()
"Return the bounds of the list at point.
Prefer the enclosing list with fallback on sexp at point.
\[Internal function used by `bounds-of-thing-at-point'.]"
(save-excursion
- (if (ignore-errors (up-list -1 escape-strings no-syntax-crossing))
+ (if (ignore-errors (up-list -1))
(ignore-errors (cons (point) (progn (forward-sexp) (point))))
(let ((bound (bounds-of-thing-at-point 'sexp)))
(and bound
(<= (car bound) (point)) (< (point) (cdr bound))
bound)))))
-(put 'list-or-string 'bounds-of-thing-at-point
- 'thing-at-point-bounds-of-list-or-string-at-point)
-
-(defun thing-at-point-bounds-of-list-or-string-at-point ()
- "Return the bounds of the list or string at point.
-Like `thing-at-point-bounds-of-list-at-point', but if
-point is inside a string that's enclosed in the list, this
-function will return the enclosed string and not the
-enclosing list."
- (thing-at-point-bounds-of-list-at-point t t))
-
;; Defuns
(put 'defun 'beginning-op 'beginning-of-defun)