Hacker News new | comments | show | ask | jobs | submit login

There is also a important lesson which goes like this: your scripts should operate on a buffer (even a temporary one) and almost never on strings. Its generally easier that way because there is so much support from all the functions already exposed to editing tasks.



Hmmm... I think I disagree with this as well... strings are very very well supported... it's a little annoying that we don't have a full string lib in elisp (some of the things here http://emacswiki.org/emacs/ElispCookbook#toc1 are missing, but that's why I say you can copy and paste when you need to).


You rather write something like this (from Emacswiki) operating on strings?

        (defun kill-whitespace ()
          "Kill the whitespace between two non-whitespace characters"
          (interactive "*")
          (save-excursion
            (save-restriction
              (save-match-data
                (progn
                  (re-search-backward "[^ \t\r\n]" nil t)
                  (re-search-forward "[ \t\r\n]+" nil t)
                  (replace-match "" nil nil))))))


it depends on the context... but maybe replace-regexp-in-string would be the right function to use for strings in this context.

Of course, a lot of the time buffers are really powerful tools to replace strings. I just don't think your original assertion of "almost never" is right. Buffers are handy but I use them to replace strings less than 50% of the time.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: