0

If I search for "c#" or anything with special characters, they somehow get removed.

Not sure which part of this removes the "#";)

(defun w3m-lookup-first-clipboard-item ()
  "Look up the current word's definition in a browser.
If a region is active (a phrase), lookup that phrase."
 (interactive)
 (let (myword myurl)
   (setq myword (current-kill 0))
  (setq myword (replace-regexp-in-string " " "%20" myword))
  (setq myurl (concat "https://www.google.com/search?q=" myword))
  ;;(browse-url myurl)
  (w3m-browse-url myurl)
   ))

NickD
  • 27,023
  • 3
  • 23
  • 42
Jason Hunter
  • 519
  • 2
  • 9

1 Answers1

2

Not sure which part of this removes the "#";)

Nothing in your posted code removes the "#". Remember that a "#" specifies an anchor in a url. https://www.google.com/search?q=c# is a url with a null anchor, and so is getting reduced to https://www.google.com/search?q=c. Instead of using replace-regexp-in-string on your search term try url-hexify-string instead. This will "escape" non-reserved characters (the space character, some symbols, etc.) as percent-delimited hex values.

(defun w3m-loopup-first-clipboard-item ()
  "Look up the current word's definition in a browser.
If a region is active (a phrase), lookup that phrase."
  (interactive)
  (let (myword myurl)
    (setq myword (current-kill 0))
    (setq myword (url-hexify-string myword))
    (setq myurl (concat "https://www.google.com/search?q=" myword))
    ;;(browse-url myurl)
    (w3m-browse-url myurl)
    ))

nega
  • 3,091
  • 15
  • 21