[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/webpaste cd66756 241/298: Detect lang from shebang
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/webpaste cd66756 241/298: Detect lang from shebang |
Date: |
Thu, 9 Dec 2021 19:00:22 -0500 (EST) |
branch: elpa/webpaste
commit cd667565f305b97e1711a05a0a063b300b0beda1
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
Detect lang from shebang
Update the lang alist for ptpb.pw for bash, sh, csh, tcsh, python3 and
nim.
Fixes https://github.com/etu/webpaste.el/issues/28.
---
webpaste.el | 41 +++++++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/webpaste.el b/webpaste.el
index ce12f2e..3665a38 100644
--- a/webpaste.el
+++ b/webpaste.el
@@ -93,7 +93,13 @@ This uses `browse-url-generic' to open URLs."
:lang-uri-separator "/"
:lang-overrides ((emacs-lisp-mode . "elisp")
(nix-mode . "nix")
- (conf-toml-mode . "toml"))
+ (conf-toml-mode . "toml")
+ (bash-mode . "bash")
+ (sh-mode . "sh")
+ (csh-mode . "csh")
+ (tcsh-mode . "tcsh")
+ (python3-mode . "python3")
+ (nim-mode . "nim"))
:success-lambda webpaste--providers-success-location-header)
("ix.io"
@@ -399,6 +405,32 @@ Optional params:
webpaste-provider-priority)
+(cl-defun webpaste--get-shebang-lang-mode ()
+ "Return language of the buffer set using a shebang as a mode symbol.
+
+Return nil if no shebang found.
+
+Example: For \"#!/usr/bin/env bash\", 'bash-mode is returned.
+ For \"#!/bin/python\", 'python-mode is returned."
+
+ (let* ((end-of-first-line (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (end-of-line 1)
+ (point))))
+ (first-line (save-restriction
+ (widen)
+ (buffer-substring-no-properties
+ (point-min) end-of-first-line))))
+ (when (string-match "\\`#!\\(?1:\\(?:[^ ]+/\\)\\(?2:[^ /]+\\)\\)\\(?:
+\\(?3:[^ ]+\\)\\)*" first-line)
+ (let ((lang (if (string= "/usr/bin/env" (match-string-no-properties 1
first-line))
+ (match-string-no-properties 3 first-line)
+ (match-string-no-properties 2 first-line))))
+ (when lang
+ (intern (format "%s-mode" lang)))))))
+
+
(cl-defun webpaste--get-buffer-language (provider)
"Return language of the buffer that should be sent to the PROVIDER.
@@ -406,9 +438,10 @@ This also depends on which provider it is since different
providers might have
different opinions of how the input for their fields should look like."
(unless webpaste-paste-raw-text
- (let ((provider-lang-alist (cdr (assoc provider
webpaste--provider-lang-alists))))
- (let ((language-name (cdr (assoc major-mode provider-lang-alist))))
- language-name))))
+ (let* ((provider-lang-alist (cdr (assoc provider
webpaste--provider-lang-alists)))
+ (detected-mode (or (webpaste--get-shebang-lang-mode) major-mode))
+ (language-name (cdr (assoc detected-mode provider-lang-alist))))
+ language-name)))
(cl-defun webpaste--return-url (returned-url)
- [nongnu] elpa/webpaste cc9ba3d 202/298: Begin autoloading of the webpaste group, (continued)
- [nongnu] elpa/webpaste cc9ba3d 202/298: Begin autoloading of the webpaste group, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste aed3e00 210/298: Bump version for new release, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste b8f300f 209/298: Add pattern for buttercup to not run gists.github.com on travis, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 4bd15f8 227/298: Add a nix-shell file for some development utils, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste f047313 219/298: Update the custom hook example to actually need to be a lambda, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste ac24701 214/298: Merge branch 'DamienCassou-simplify-travis', ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 6a02ff9 185/298: Added tests for error lambdas and failovers, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste bf08207 211/298: Update my name due to legal namechange, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 14fd97b 225/298: Add deprecation message of simpleclip option to clean up the code, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste b6f8005 216/298: Do not fallback to true if test fails, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste cd66756 241/298: Detect lang from shebang,
ELPA Syncer <=
- [nongnu] elpa/webpaste 1787ea7 249/298: bugfix in "gist.github.com" entry of webpaste-providers-alist, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 9da4eca 258/298: travis: Switch to nix-emacs-ci, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 7d08f87 254/298: integration-tests: Change filtering of local/ci provider tests, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste afbcf6f 273/298: Merge branch 'comfort-paste', ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 4e410b0 272/298: Add example config to README with 'pasting buffer OR region' function, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 0760361 278/298: docs: Fix all warnings regarding docstrings, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 5e963e8 275/298: Fix bug in webpaste-paste-buffer-or-region when you don't have a region, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 9662b1c 280/298: Bump version number and copyright year, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 3c9d2e8 284/298: Merge branch 'github-actions', ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 4ec1645 297/298: Readme: Update branch name, ELPA Syncer, 2021/12/09