Q:

How can I make emacs ignore part of the file name when deciding major mode?

If you have a GPG-encrypted file, say notes.org.gpg, emacs figures out that the major mode has to be set to org-mode. This applies in general to any major mode out there; you do not need to modify the auto-mode-alist for each major mode to support that .gpg extension.
I would like to have my own extra extension, let's say .~bkp~ and have emacs ignore that when determining the major mode. Currently, if I have a file named notes.org.~bkp~, the org-mode is not set automatically.
I scoured through files.el, epa*.el, googled but couldn't figure out how emacs is ignoring the .gpg in the file names.
What function can I probably advice or a variable can I tweak to support my custom appended extensions?

A:

The relevant entry in auto-mode-alist is this:
 ([...] ("\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" nil epa-file) [...])

And here is the documentation that describes what is going on:

auto-mode-alist is a variable defined in files.el.
This variable may be risky if used as a file-local variable.
Documentation:
  Alist of filename patterns vs corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). (NON-NIL stands for anything that is not nil; the value does not matter.) Visiting a file whose name matches REGEXP specifies FUNCTION as the mode function to use. FUNCTION will be called, unless it is nil.
If the element has the form (REGEXP FUNCTION NON-NIL), then after
  calling FUNCTION (if it's not nil), we delete the suffix that matched
  REGEXP and search the list again for another match.
The extensions whose FUNCTION is archive-mode should also appear in auto-coding-alist with no-conversion coding system.
See also interpreter-mode-alist, which detects executable script modes based on the interpreters they specify to run, and magic-mode-alist, which determines modes based on file contents.
[...]

So there you go!
(add-to-list 'auto-mode-alist '("\\.bkp\\(~[0-9_]+~\\)\\'" nil backup-file))

