Skip to content

Add auto-mode-alist for /config.php #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Add auto-mode-alist for /config.php #363

wants to merge 1 commit into from

Conversation

zonuexe
Copy link
Member

@zonuexe zonuexe commented Jul 2, 2017

refs #362

Currently, many php-mode users can not open config.php.
When php-mode is auto loaded, its priority is lower in auto-mode-alist
due to the append flag of add-to-list. Because of that, /config.php
matches conf-maybe-mode.

This patch is explicitly added to avoid conflict with the default
conf-maybe-mode in auto-mode-alist.

refs #362

Currently, many php-mode users can not open config.php.
When php-mode is auto loaded, its priority is lower in auto-mode-alist
due to the append flag of add-to-list. Because of that, /config.php
matches conf-maybe-mode.

This patch is explicitly added to avoid conflict with the default
conf-maybe-mode in auto-mode-alist.
;; refs https://github.com/ejmr/php-mode/pull/362#issuecomment-312404436
;; To avoid conflict with default `conf-maybe-mode' in auto-mode-alist, add it explicitly.
(add-to-list 'auto-mode-alist '("[/.]c\\(?:on\\)?f\\(?:i?g\\)?\\(?:\\.[a-zA-Z0-9._-]+\\)?\\.php[s345t]?\\'" . php-mode)))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also match cfg.php? In my opinion this is an example of a regular expression becoming too complex; we have multiple regular expressions like this which I believe we should gradually replace. Even though it would be more verbose, we can and I think should rewrite this regular expression now to use (rx ...) so that it will be easier to understand exactly what we are matching.

Alternatively, or even together with (rx ...), I think it is better to use a separate call to add-to-list to cover the situation of config.php. Having a separate call like (add-to-list 'auto-mode-alist '("regex for config.php" . php-mode)) will create a tiny amount of code duplication---we don't need two calls to add-to-list---but in this scenario I believe it helps readability and maintainability.

Copy link
Member Author

@zonuexe zonuexe Jul 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is a modification of copying from files.el.

;; Original code: https://github.com/emacs-mirror/emacs/blob/65eee8392ff95f58f7b0bd036e1fe065523658c6/lisp/files.el#L2620
     ("[/.]c\\(?:on\\)?f\\(?:i?g\\)?\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-mode-maybe)

I think that rewriting this regexp pattern to rx is not appropriate.

@ejmr
Copy link
Collaborator

ejmr commented Jul 24, 2017

I apologize for the long delay but I finally had time to merge this tonight. Thank you for all your continued work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants