1

There is a function in ESS called ess-sas-goto-log (https://github.com/emacs-ess/ESS/blob/master/lisp/ess-sas-a.el#L705) that will open a log file and search forward using re-search-forward. I would like to make a version that searches backwards. What would be the best way to go about this?

I know I can simply replace search-forward with search-backward but I would like to do it the proper way.

Thanks!

4
  • 2
    It is a matter of taste / personal preference. I am the only person I know who likes to modify the source code directly and take complete control. Most everyone else in the world goes out of his/her way to try and figure out how to use advice if at all possible, and everyone (but me) seems to love/up-vote that approach. A small handful of people post answers that use (require 'name-of-library) followed by the new revised function with the same name so that the old function gets redefined. And there are a small minority of people who might create a new function and use defalias. – lawlist Sep 2 '16 at 15:31
  • 1
    And, see also this related thread that redefines a function on a temporary basis using cl-letf: emacs.stackexchange.com/a/22571/2287 I have a comment underneath the answer that demonstrates how I applied it to my particular use-case. I don't see a lot of answers using that, perhaps because it is a little advanced -- but it sure is nifty (in my opinion). On another note, there is a very important distinction between search-forward versus re-search-forward and search-backward versus re-search-backward. One uses a literal string, whereas the other searches by a regexp. – lawlist Sep 2 '16 at 15:53
  • Too broad. Specify what you mean by "best". Just what are you looking for? – Drew Sep 2 '16 at 18:14
  • Yes, I realize that "best" isn't the best word. I am looking for what were accepted conventions of re-purposing an existing function such that it avoids breaking and headaches. lawlist pretty much answer the questions I had. Many thanks! – Jorge T Leon Sep 2 '16 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.