2

Some files in Emacs should not be modified, for example:

  1. an .el.gz library file which is expected to behave "properly"
  2. an external extension, which will be overwritten on update

Anyway, there are ways to change default behaviours but not through changing of the source code bundled with Emacs or it's packages.

What are the best ways to prevent oneself (or at least warn) from editing those files.

Łukasz Gruner
  • 1,008
  • 8
  • 16

1 Answers1

2

Safe way to tweak an emacs uilt-in or 3rd party function

You can always re-define a function defined in the source code.

In the emacs SE question How do I disable ffap (find file at point) when the first two non-space characters in a line are '//'?, Sigma suggested in his answer to re-define the ffap-string-at-point function to solve the problem described in that question.

How can one avoid re-defining built-in functions by mistake

  • You can adopt a practice to use a prefix like my/ for your own functions and variables. e.g. my/find-file. That way you can be rest assured that you are not overriding any of the emacs built-in functions/variables.
  • Before defining a new function of your own, you can check if an interactive function by the same name already exists by doing C-hf FUNCTION-NAME. If that function exists, you will see its description.
  • You can grep for a function or variable name in emacs source code and elpa folder to check if that function/variable already exists.

The easiest way to be safe is the first bullet mentioned above.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
  • But I want to keep myself from (accidentaly) changing stuff that is part o emacs or that will be updated/overwritten sometime in the future. – Łukasz Gruner Nov 07 '14 at 21:52
  • If it's a package/elisp code that you did not write, then whether you re-define a function or use defadvices, it is very likely that that will break when the code author makes any changes in the original code. This applies to the emacs lisp source code and 3rd party packages. If you are using patched functions, it is your job to see that they stay updated with the source code. Can you specify what code are you trying to modify? – Kaushal Modi Nov 07 '14 at 22:54
  • I'm not modyfiyng anything, I just dont want to accidentally change build-in Emacs function. – Łukasz Gruner Nov 08 '14 at 03:03
  • @ŁukaszGruner I have updated my answer with few tricks I know of how to avoid redefining pre-existing functions/vars. – Kaushal Modi Nov 08 '14 at 05:19